0
votes

I'm just starting a new project using NativeScript + Angular and have hosted the code in Visual Studio Team Services. I'm brand new to NativeScript however I want to have a Build Definition setup to build the iOS and Android artifacts for Continuous Integration.

When I build locally, I do the following command: tns build however I'm unclear how I would be able to use this in a Team Services Build Definition. Right now my build definition only consists of

  1. Get Sources
  2. npm install
  3. ??? (where I'd like to do tns build here)

It currently fails because it doesn't know what the tns command is and as far as I'm aware, I cannot install these tools on an agent since its a hosted instance. Appreciate any thoughts or alternative ideas!

3

3 Answers

0
votes

Here's the answer, you need to set your global directory and add it to the path. Feel free to remove the debugging comments.

echo 'This is the current path.'
echo $PWD
echo 'This is the global path.'
npm prefix -g 
echo 'Setting the npm prefix path'
npm config set prefix "$PWD/NPM"
echo 'Setting path'
PATH=$PATH:"$PWD/NPM/bin"
npm install nativescript -g

echo "PATH: $PATH"
tns doctor
0
votes

I was able to get this working. I did this yaml pipeline in Azure Devops.

For ios

- task: UseNode@1
      displayName: "Use Node ${{ parameters.nodeVersion }}"
      inputs:
        version: XX.XX
    - task: Npm@1
      displayName: 'npm clean'
      inputs:
        command: custom
        verbose: false
        customCommand: 'run clean'
    - task: Npm@1
      displayName: 'npm install nativescript'
      inputs:
        command: custom
        verbose: false
        customCommand: 'install nativescript@6 -g'
    - task: PythonScript@0
      displayName: "Install python package six"
      inputs:
        scriptSource: 'inline'
        script: |
          import os
          os.system("pip install six")
    - task: InstallAppleProvisioningProfile@1
      displayName: "Install an Apple provisioning profile"
      inputs:
        provisioningProfileLocation: 'secureFiles'
        provProfileSecureFile: ${{ parameters.iosProvisionProfile }}
    - task: InstallAppleCertificate@2
      displayName: "Install an Apple certificate"
      inputs:
        certSecureFile: 'devops-cn.p12'
        certPwd: ${{ parameters.certificatePassword }}
        keychain: 'temp'
        signingIdentity: 'iPhone Distribution: Whatever Company'
    - task: PythonScript@0
      displayName: "Build"
      env:
        IOS_PROVISION_PROFILE_NAME: ${{ parameters.iosProvisionProfileName }}
        IOS_IPA_FILE_NAME: ${{ parameters.iosIpaFileName }}
      inputs:
        scriptSource: 'inline'
        script: |
          import os, shutil
          os.system("tns build ios --bundle --provision \"{}\" --for-device --release".format(os.environ.get('IOS_PROVISION_PROFILE_NAME')))

For Android

- task: UseNode@1
  displayName: "Use Node XX.XX"
  inputs:
    version: XX.XX
- task: Npm@1
  displayName: "npm install"
  inputs:
    command: 'custom'
    customCommand: 'run clean'
- task: Npm@1
  displayName: "npm install nativescript"
  inputs:
    command: 'custom'
    customCommand: 'install nativescript@6 -g'
- task: PythonScript@0
  displayName: "Build"
  env:
    AND_KEY_STORE_PASSWORD: ${{ parameters.androidKeyStorePassword }}
    AND_KEY_STORE_ALIAS: ${{ parameters.androidKeyStoreAlias }}
    AND_KEY_STORE_ALIAS_PASSWORD: ${{ parameters.androidKeyStoreAliasPassword }}
  inputs:
    scriptSource: 'inline'
    script: |
      import os
      
      os.system("tns build android --bundle --release --key-store-path \"$(secureFile.secureFilePath)\" --key-store-password \"{}\" --key-store-alias \"{}\" --key-store-alias-password \"{}\"".format(os.environ.get('AND_KEY_STORE_PASSWORD'), os.environ.get('AND_KEY_STORE_ALIAS'),  os.environ.get('AND_KEY_STORE_ALIAS_PASSWORD')))
-1
votes

You need to add install NativeScript Command-Line interface by using NPM task, for example:

  1. NPM task 1.* (Command: custom; Command and arguments: install nativescript –g)
  2. Command Line (call tns command) (Tool: tns; Arguments: --help)

On the other hand, you can setup a private build agent, then running it as your account (change service account)

Note: Based on my test, it works fine with Hosted Linux Preview agent; it throws error with Hosted agent (not supported platform)