lerna on AzureDevops - azure-devops

I am trying to make an azure Pipeline CI CD .
I want have some dependencies in my project like Lerna .
so i tried to install it but i am getting an error that the command is not found when i try to build it
Thats my azure-pipelines.yml
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- release
pool:
vmImage: "ubuntu-latest"
steps:
- task: NodeTool#0
inputs:
versionSpec: "10.0.0"
displayName: "Install Node.js"
- task: HelmInstaller#1
inputs:
helmVersionToInstall: 'latest'
- script: |
yarn global add lerna
yarn global add #gov.au/pancake
yarn install
displayName: "install lerna & pancake packages"
- script: |
yarn run build
displayName: "NPM build"
- script: |
export NODE_OPTIONS=--max-old-space-size=8192
displayName: "set Env Variable "
- script: |
lerna run build --stream --concurrency=1 --include-dependencies
lerna run docker-build-local --stream --concurrency=4 --include-filtered-dependencies
displayName: "Build lerna "
and i am getting an error in the last script although lerna is installed
/bin/bash --noprofile --norc /home/vsts/work/_temp/2d7931d0-403d-45a0-b7c9-9dfd7b5325f4.sh
/home/vsts/work/_temp/2d7931d0-403d-45a0-b7c9-9dfd7b5325f4.sh: line 1: lerna: command not found
/home/vsts/work/_temp/2d7931d0-403d-45a0-b7c9-9dfd7b5325f4.sh: line 2: lerna: command not found
##[error]Bash exited with code '127'.

Related

Implement/integrate ESLint in SonarQube?

I would like to ask how can I implement the ESLint on our Azure Pipeline? I do not have enough knowledge on Azure Pipelines and SonarQube, and I also am not so sure about ESLint. So far, here's the script I have. Although this is pretty much from the available tasks. I'd like to implement the ESLint on SonarQube like on this link: https://docs.sonarqube.org/pages/viewpage.action?pageId=11639183
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
checkLatest: true
displayName: 'Install Node.js'
- task: Npm#1
inputs:
command: 'install'
displayName: 'NPM Install'
- script: |
npm bin -g
displayName: 'Check path'
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'test' #from the package.json
This one here is from the npm bin -g:
##[debug] /home/vsts/work/_temp/5b2e34ae-e8f8-4e24-a539-9d41f7435789.sh
/bin/bash --noprofile --norc /home/vsts/work/_temp/5b2e34ae-e8f8-4e24-a539-9d41f7435789.sh
/opt/hostedtoolcache/node/10.23.1/x64/bin
##[debug]Exit code 0 received from tool '/bin/bash'
##[debug]STDIO streams have closed for tool '/bin/bash'
##[debug]task result: Succeeded
##[debug]Processed: ##vso[task.complete result=Succeeded;done=true;]
Here's the error from the last task.
##[debug]Agent.BuildDirectory=/home/vsts/work/1
##[debug]rm -rf /home/vsts/work/1/npm
##[debug]removing directory
##[debug]task result: Failed
##[error]Error: Npm failed with return code: 1
##[debug]Processed: ##vso[task.issue type=error;]Error: Npm failed with return code: 1
##[debug]Processed: ##vso[task.complete result=Failed;]Error: Npm failed with return code: 1
Here's a bit of copy from my package.json:
"scripts": {
"lint": "npm run lint:lwc && npm run lint:aura",
"linter": "./node_modules/.bin/eslint ./",
"lint:aura": "eslint **/aura/**",
"lint:lwc": "eslint **/lwc/**",
"test": "npm run test:unit",
There is not tasks or commands in your yaml pipeline to run the linter. You can add a script task or npm task to run the linter. See below:
Add a npm task to run linter.
- task: Npm#1
inputs:
command: 'install'
displayName: 'NPM Install'
- task: Npm#1
displayName: 'Linter'
inputs:
command: 'custom'
customCommand: 'run linter'
Or add a script task to run linter:
- task: Npm#1
inputs:
command: 'install'
displayName: 'NPM Install'
- script: |
npm run linter
npm run lint #run npm run lint:lwc && npm run lint:aura in your package.json
Before you can run above linter commands in azure pipeline. You need to add eslint dependency to your project and generate your ESLint config file on your local machine.
Run below commands on your local repo and then push to your source server.
Add eslint dependency:
npm install eslint --save-dev
Generate ESLint config file
./node_modules/.bin/eslint --init
You can check out this blog.

How to manually add "script" in an Azure CI Pipeline?

I have a node.js/typescript/angular project in BitBucket that I want to create a build (CI) pipeline for it on Azure Devops. I used the classic editor to create the pipeline (reason below) and am trying to add the following task(s)/step(s):
npm install #types/node#8.10.52
ng build (ng is angular)
If was to use the YAML configuration, the resulting YAML file looks like the following file below, so how do i create a "script" manually after the Node task i have in classic editor? I only have options to add "npm" as a task, which is why i have added 3 npm tasks as shown in image above with 3 separate custom commands to mimic the steps configuration in the YML file below. Is that the way to do it with custom command?
YAML file npm/angular representation via YAML configuration:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install -g #angular/cli
npm install
ng build --prod
displayName: 'npm install and build'
Reason why Im using classic editor:
When i tried saving the YAML configuration pipeline, i got a "Error from bitbucket: something went wrong" error, which appears to be a write-permission issue based on what i found from Atlassian forums.
So i ended up just using the classic pipeline editor, and this way i was able to select a specific branch (i.e. dev) instead of master (prod) branch.
The way I've handled this is to add a script to your package.json:
"scripts": {
"ng": "ng",
"build": "ng build",
"build-prod": "ng build --configuration=production"
"build-dev": "ng build --configuration=dev"
},
...
Then, you just call run-script from the custom NPM task:
Or you could optionally on the task just call run-script build --prod since you can pass arguments on the task.
These same steps are available in YAML, it would look something like this:
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install node.js'
- task: Npm#1
inputs:
command: 'install'
displayName: npm install
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'run-script build --prod'
displayName: 'npm build'

can't find package.json when running cypress test in azure pipeline yaml

I'm trying to run a cypress test in an Azure Pipeline job using YAML. When the pipeline runs, it gets to the line where the cypress test runs and throws this error:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\myagent\_work\5\s\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\myagent\_work\5\s\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
Here is my YAML file:
trigger:
- master
pool:
name: Default
variables:
buildConfiguration: 'Release'
steps:
- task: NodeTool#0
displayName: 'Use Node 12.x'
inputs:
versionSpec: 12.18.3
checkLatest: false
- task: Npm#1
displayName: 'npm install'
inputs:
workingDir: WebApp
verbose: false
- task: Npm#1
displayName: 'Build Angular'
inputs:
command: custom
customCommand: run build -- --prod
workingDir: WebApp
- task: UseDotNet#2
displayName: 'Use .NET Core SDK 3.1.300'
inputs:
packageType: sdk
version: 3.1.300
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: AppApi/AppApi.csproj
vstsFeed: '*************'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: publish
arguments: '--no-restore --configuration $(buildConfiguration) --verbosity quiet --output $(build.artifactstagingdirectory)'
publishWebProjects: true
zipAfterPublish: true
- script: 'npx cypress verify'
displayName: 'cypress verify'
failOnStderr: true
- script: 'npm run cy:run --headless --spec cypress/integration/TestDemoExpanded.spec.ts --project ./WebApp'
displayName: 'run cypress tests'
workingDirectory: $(Build.SourcesDirectory)/WebApp
My package.json is checked into my Git repository and is located in my WebApp subfolder. How do I solve this error?
UPDATED:
I added the workingDirectory parameter as suggested but now I have this new error: npm ERR! missing script: cypress
I solved the 'missing script' error. The cypress run command I had in my YAML file didn't match the cypress run command I had in my package.json. I updated the cypress run step and now the tests run in the pipeline.
The task searches the package.json in the root folder and not in WebApp.
Just add:
workingDirectory: $(Build.SourcesDirectory)/WebApp
To the cypress step:
- script: 'npm run cypress run --headless --spec cypress/integration/TestDemoExpanded.spec.ts --project ./WebApp'
displayName: 'run cypress tests'
workingDirectory: $(Build.SourcesDirectory)/WebApp

Azure Devops handle special character in yaml

I have problem with the Azure Devops yaml script, as it doesn't pick up my variable properly to build my ReactJS project. Below is the script, but somehow the build failed at git push, and the username does't get picked up
pool:
vmImage: 'Ubuntu 16.04'
steps:
- task: NodeTool#0
inputs:
versionSpec: '9.8.0'
displayName: 'Install Node.js'
- script: |
npm install --no-save
npm run build
git push https://"$(azure.Username)":$(azure.Password)#$(azure.AppName).scm.azurewebsites.net:443/$(azure.AppName).git master
displayName: 'npm install and build'
My solution as per the yml file below, and you can set the variable to have "$" sign in it. Another better way is to use the steps in Azure DevOps itself.
image: node:9.8.0
clone:
depth: full
pipelines:
default:
- step:
script:
- npm install --no-save
- npm run build
- git push https://$AZURE_LOGIN:$AZURE_PASSWORD#$AZURE_APP_NAME.scm.azurewebsites.net:443/$AZURE_APP_NAME.git master
The correct answer is to wrap the variable in single quotes as such: '$(myVariable)'. This prevents the yaml parser from parsing the contents of the variable

Visual Studio Team Services - How to Setup a NativeScript Build?

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
Get Sources
npm install
??? (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!
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
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')))
You need to add install NativeScript Command-Line interface by using NPM task, for example:
NPM task 1.* (Command: custom; Command and arguments: install nativescript –g)
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)