I want to run a Bash script in an Azure DevOps Pipeline, see below my yaml file:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '12.x'
displayName: 'Install Node.js'
- task: Bash#3
inputs:
targetType: 'filePath'
filePath: 'build.sh'
The pipeline is calling a "build.sh" script that calls node.js, and that is why I install the tool before running the script. However, I get the following message:
/home/vsts/work/1/s/build.sh: line 5: nodejs: command not found
This is the line 5 in the "build.sh" script, and it is working when I run it directly from my computer:
nodejs ../bin/r.js -o baseUrl=. optimize=none name=main out=main-built.js exclude=jquery.js
I have tried different approaches but cannot make it work. Any hint?
Please use node instead if nodejs
steps:
- task: NodeTool#0
inputs:
versionSpec: '12.x'
displayName: 'Install Node.js'
- task: Bash#3
inputs:
targetType: 'inline'
script: 'node --version'
- task: Bash#3
continueOnError: true
inputs:
targetType: 'inline'
script: 'nodejs --version'
then I got for node --version
v12.19.0
and for nodejs --version
/home/vsts/work/_temp/6287b2ad-1b03-48fd-a4df-3cf7ad6c9971.sh: line 1: nodejs: command not found
Related
The default .yaml file provided by the ADO pipeline fails. There's been an issue open for over a year on it and the problem still exists.
I tried this .yaml file from learn.microsoft but it fails with the error below. Does someone have a .yaml file that works for a Go pipeline in Azure DevOps?
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: GoTool#0
inputs:
version: '1.13.5'
- task: Go#0
inputs:
command: 'get'
arguments: '-d'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: Go#0
inputs:
command: 'build'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: CopyFiles#2
inputs:
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
artifactName: drop
Here's the error:
##[section]Starting: Go
==============================================================================
Task : Go
Description : Get, build, or test a Go application, or run a custom Go command
Version : 0.210.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/go
==============================================================================
[command]/opt/hostedtoolcache/go/1.13.5/x64/bin/go get -d
go get .: path /home/vsts/work/1/s is not a package in module rooted at /home/vsts/work/1/s
##[error]The Go task failed with an error: Error: The process '/opt/hostedtoolcache/go/1.13.5/x64/bin/go' failed with exit code 1
##[section]Finishing: Go
Just try this :
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: GoTool#0
inputs:
version: '1.13.5'
- task: Go#0
inputs:
command: 'get'
arguments: '-v all'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: Go#0
inputs:
command: 'build'
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: CopyFiles#2
inputs:
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
artifactName: drop
I have an azure function app that is running on Azure. I am now trying to configure the application based on a powershell script. This powershell script is being used to create azure resources (Ex: KeyVault, ApplicationInsights...) that will be then used by the function app. I created the powershell script and my question here is how can I add the powershell script in the yaml file which is responsible to deploy the application. The powershell script is located in the repository under the name functionapp.ps1 . The idea here is to run the powershell script once the build is finished so in the deploy stage. What I did so far is the following:
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: 'build'
projects: |
$(workingDirectory)/*.csproj
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: CmdLine#2
inputs:
script: |
echo '$(System.DefaultWorkingDirectory)'
dir
- task: PowerShell#2
inputs:
targetType: 'filePath'
filePath: $(System.DefaultWorkingDirectory)/functionapp.ps1
- task: AzureFunctionApp#1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionApp
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
When the stages are being run and it arrives to this task I get the following error:
##[error]Invalid file path 'D:\a\1\s\functionapp.ps1'. A path to a .ps1 file is required.
I tried using the command line task to check the default working directory and I got the following result: D:\a\1\s
I still don't know what I am missing here and why I am getting this error. Can someone please give me a concrete solution to this problem ?
I ended up having the same error. Can someone please tell me what is the issue here ?
I am trying to integrate storybook/chromatic into my azure pipeline, however i am getting the following error:
/home/vsts/work/_temp/60ae6370-8818-4ab7-a2d8-f4a0443fadf9.sh: line 1: --project-token=${project_token}: bad substitution
I followed this https://www.chromatic.com/docs/azure-pipelines
I did obviously put my project token where it was needed.
Based on the error message, it seems that this issue comes from a script format or symbol.
I have tested the YAML sample from the link you shared and it can work fine.
Here are my steps, you can refer to them.
Step1 : Set the variable CHROMATIC_PROJECT_TOKEN
Step2: Run the YAML sample:
stages:
- stage: Test
displayName: Chromatic Testing
# Job list
jobs:
- job: Chromatic_Deploy
displayName: Install packages and publishes to Chromatic
steps:
- task: NodeTool#0
inputs:
versionSpec: '12.x'
displayName: 'Install Node.js'
- task: Npm#1
inputs:
command: 'install'
workingDir: '$(build.sourcesdirectory)'
- task: CmdLine#2
displayName: Publish to Chromatic
inputs:
script: npx chromatic --project-token=${CHROMATIC_PROJECT_TOKEN}
Here is my result:
You can also try to use --project-token=$(CHROMATIC_PROJECT_TOKEN) in the YAML sample.
When running a build for storybook via an Azure devops pipeline I get the above mentioned error.
I've tried to completely remove this package(plottable) from my project but I keep getting this error and it causes my webpack build to get stuck.
This error doesn't occur locally.
My pipeline:
trigger:
batch: true
branches:
include:
- master
stages:
- stage: develop_build_deploy_stage
pool:
name: Default
demands:
- msbuild
- visualstudio
jobs:
- job: develop_build_deploy_job
steps:
- checkout: self
clean: true
persistCredentials: true
- task: NodeTool#0
displayName: Install Node
inputs:
versionSpec: '12.x'
- task: PowerShell#2
displayName: 'Install Dependencies'
inputs:
targetType: 'inline'
script: |
npm install
- task: PowerShell#2
displayName: 'Increment version'
inputs:
targetType: 'inline'
script: |
git checkout master
git pull origin master
git config --global user.email "d#gmail.com"
git config --global user.name "Build Agent"
npm version patch -m "Increment Version [skip ci]" --force
git push
- task: PowerShell#2
displayName: 'Build Project'
inputs:
targetType: 'inline'
script: |
npm run build-storybook
npm run build
- task: CopyFiles#2
displayName: 'Copy storybook-static Files'
inputs:
sourceFolder: '$(Build.SourcesDirectory)/storybook-static'
contents: '**'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish storybook-static Files to ArtifactStagingDirectory'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: Storybook
- task: S3Upload#1
displayName: 'Upload storybook-static to S3'
inputs:
awsCredentials: 'my-s3'
regionName: 'us-east-1'
bucketName: 'my-s3-bucket'
sourceFolder: $(Build.ArtifactStagingDirectory)
- task: Npm#1
displayName: 'Publish to Feed'
inputs:
command: 'publish'
publishRegistry: 'useFeed'
publishFeed: '#####'
How would I go about resolving this problem?
I still don't know what caused this to be the case but for some reason the changes I had made on my branch weren't being picked up and an import that I had removed wasn't removed on the branch that was being built on.
So in the end it was trying to import a package which I had removed as a dependency.
I am trying to run some unit tests in my azure pipeline but it keeps saying 'Waiting for console output'. This goes on for about an hour until it eventually fails. I do not understand why it can't access the output from console. New to working with Azure/pipelines in general and any help would be appreciated. Thank you.
Here is my yaml file:
pr:
- $(branch)
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.14'
displayName: 'Install Node.js'
- script: |
npm install -g #angular/cli
npm install
displayName: 'Install Angular Dependencies'
- task: Npm#1
displayName: 'Lint Angular'
inputs:
command: custom
customCommand: run lint -- --format=stylish
- script: |
npm run test
displayName: 'Run Unit Tests'
- task: PublishTestResults#2
displayName: 'Publish unit tests results'
condition: succeededOrFailed()
inputs:
searchFolder: $(System.DefaultWorkingDirectory)/src/tests/junit
testRunTitle: Angular
testRunner: JUnit
testResultsFiles: "**/TESTS-*.xml"
- task: PublishCodeCoverageResults#1
displayName: 'Publish unit test code coverage results'
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/src/tests/coverage/cobertura-coverage.xml
reportDirectory: $(System.DefaultWorkingDirectory)/src/tests/coverage
failIfCoverageEmpty: true
- script: |
$(npm-script)
displayName: 'Build App'
- script: |
cd $(System.DefaultWorkingDirectory)/
ls -a
cp -r dist $(Build.ArtifactStagingDirectory)/
cp ecosystem.config.js $(Build.ArtifactStagingDirectory)/
cd $(Build.ArtifactStagingDirectory)/
ls -a
# rm -r node_modules
# ls -a
displayName: 'Copy Files to Archive'
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' # '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- script: |
cd $(System.DefaultWorkingDirectory)/
ls -a
cd $(Build.ArtifactStagingDirectory)/
ls -a
displayName: 'Check Files 2'
- task: CopyFiles#2
displayName: 'Copy File to: $(TargetFolder)'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)/'
Contents: '$(Build.ArtifactStagingDirectory)/**/*.zip'
TargetFolder: '$(Build.ArtifactStagingDirectory)/ArtifactsToBePublished'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: App'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/ArtifactsToBePublished'
# - script: |
# npm run pre-e2e
# npm run e2e
# displayName: 'Run E2E Tests'
- script: |
pwd
cd $(Build.ArtifactStagingDirectory)/ArtifactsToBePublished
ls -a
displayName: 'See Content'
I can reproduce the same issue with npm run test script. You can have a try running unit tests with Npm task instead of using script task.
- task: Npm#1
displayName: 'Unit Test'
inputs:
command: custom
customCommand: run test -- --watch=false --code-coverage
Or
- task: Npm#1
displayName: 'Test e2e Angular'
inputs:
command: custom
customCommand: run e2e
I came across with this issue today and, based on this hint, I figured out that the browser was preventing some events from happening. So I disabled my ad blocker—in my case, Brave Shield, because I use Brave browser—and the problem is solved.