azure-devopsyamlazure-pipelinesazure-pipelines-yaml

Use script file in Azure Devops yaml deployment pipeline


In my build pipelines I make use of several bash scripts, references to with the Bash@3 task as below.

Now I try to use a script in a deployment, and I can't seem to find the script files. I've searched through the agent disk with tree command from several paths, even from the root, but the bash_scripts directory is nowhere to be found.

See # comments in snippet below for explanation.

trigger: none

pool:
  vmImage: ubuntu-latest

variables:
- template: ./variables/dev-variables.yml # Works
- template: ./variables/common-variables.yml # Works

stages:
- stage: DeployToDev
  displayName: Deploy to Dev Environment
  jobs:
  - template: ./jobs/get-docker-tags.yml # Works
  - deployment: DeployToACR
    displayName: Deploy to ACR
    dependsOn: GetDockerImageTagsJob
    environment:
      name: $(adoEnvironment)
    strategy:
      runOnce:
        deploy:
          steps:
          - script: ls $(System.DefaultWorkingDirectory)
          - script: tree /home/vsts/work/
          - script: tree $(System.DefaultWorkingDirectory)
          - script: tree $(Agent.WorkFolder)
          - script: tree $(Pipeline.Workspace)
          - script: tree /
          - task: Bash@3
            displayName: 'Get Image With Tag'
            name: GetImageWithTag
            inputs:
              targetType: 'filePath'
              filePath: 'bash_scripts/getImageToDeploy.sh' # Doesn't work
... Deployment

Solution

  • A deployment job doesn't automatically checkout the source code.

    Add the following task to your steps:

    steps:
      - checkout: self
      # other tasks here
    

    See steps.checkout definition and Deployment jobs for more details.