skip to Main Content

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


  1. 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:

    search_dir=/the/path/to/base/dir
    
    for entry in "$search_dir"/*
    do
      echo "$entry"
    done
    
    Login or Signup to reply.
  2. I am afraid the issue was simply caused by the lack of targetType property of Bash pipeline task.

    We need to let the task know, we expect to run the script from Inline section rather than the script under the default File path. Thus, I can reproduce the issue and here is the fix to add targetType: 'inline' property to the task.

    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          targetDirectory=$(System.DefaultWorkingDirectory)/my_project_directory
          
          if [ ! -d "$targetDirectory" ]; then
            mkdir -p "$targetDirectory"
          fi
          
          tree $(System.DefaultWorkingDirectory)
      displayName: 'Install dependencies'
    
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search