I’m trying to run a pipeline in Azure DevOps that checks the code with Snyk and then validates the dependencies using Composer, builds the Docker image then pushes it to ACR and finally I will implement either ArgoCD or FluxCD solution for a GitOps based approach to fetch the new image from the Azure Repo when there’s a new change.
However I keep getting this error on the Docker build task as well as the Install dependencies task…I’ve been trying to troubleshoot the error but didn’t find anything relevant.
Here’s the YAML so far:
trigger:
- main
pr:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
ACRServiceConnection: 'ACRServiceConEH'
jobs:
- job: security
displayName: 'Security'
steps:
- checkout: self
- task: SnykSecurityScan@1
inputs:
serviceConnectionEndpoint: 'SnykConnection'
testType: 'code'
codeSeverityThreshold: 'high'
failOnIssues: false
projectName: '$(SNYK_PROJECT)'
organization: '$(SNYK_ORG)'
- job: composer
dependsOn: security
displayName: 'Composer Validation'
steps:
- checkout: self
- task: Bash@3
inputs:
script: |
targetDirectory=$(System.DefaultWorkingDirectory)/my_project_directory
if [ ! -d "$targetDirectory" ]; then
mkdir -p "$targetDirectory"
fi
cd "$targetDirectory"
composer install --prefer-dist --no-progress
displayName: 'Install dependencies'
- task: Bash@3
inputs:
script: composer validate --strict
displayName: 'Validate composer.json and composer.lock'
- job: build
displayName: 'Build'
dependsOn: security
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
- task: Bash@3
inputs:
script: |
docker build . --file Dockerfile --tag $(imageName):$(Build.SourceVersion)
displayName: 'Docker build'
- task: Docker@2
inputs:
containerRegistry: $(ACRServiceConnection)
repository: $(imageName)
command: 'push'
tags: '$(Build.SourceVersion)'
displayName: 'Docker push'
Starting: Install dependencies
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.236.1
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
##[error]Invalid file path ‘/home/vsts/work/1/s’.
Finishing: Install dependencies
2
Answers
This path
/home/vsts/work/1/s
is the$(System.DefaultWorkingDirectory)
.Try to check the different paths you have available; visit Microsoft’s build variables documentation, and then use a PowerShell task to display directories and check which one is the right one that contains your
my_project_directory
.Something like:
I am afraid the issue was simply caused by the lack of
targetType
property ofBash
pipeline task.We need to let the task know, we expect to run the script from
Inline
section rather than the script under the defaultFile path
. Thus, I can reproduce the issue and here is the fix to addtargetType: 'inline'
property to the task.