ejlouw
ejlouw

Reputation: 325

Project files not available in deploy job azure dev ops pipelines

The files in the related repo are available when running the Build stage of the Azure Dev Ops pipeline, but not when running the deploy stage. Any ideas as to why this would be the case?

Here is a simplified version of the yaml file:

# Deploy to Azure Kubernetes Service
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- master

resources:
- repo: self

variables:
  # Agent VM image name
  vmImageName: 'ubuntu-latest'

  # Name of the new namespace being created to deploy the PR changes.
  k8sNamespaceForPR: 'review-app-$(System.PullRequest.PullRequestId)'

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          pwd
          ls -la


- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build

  jobs:
  - deployment: Deploy
    condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
    displayName: Deploy
    pool:
      vmImage: $(vmImageName)
    environment: 'test.development'
    strategy:
      runOnce:
        deploy:
          steps:
            - task: Bash@3
              inputs:
                targetType: 'inline'
                script: |
                  pwd
                  ls -la

Additional notes: If the deploy stage is run first (the build stage is removed) the working directory is also empty.

Upvotes: 0

Views: 1176

Answers (1)

Nick Graham
Nick Graham

Reputation: 1469

The job in your Deploy stage is a deployment job rather than a standard job, deployment jobs don't automatically checkout the repo that the pipeline is based on but they do have access to any published pipeline artifacts.

You can either publish a pipeline artifact in the Build stage or add a task to your Deploy stage to explicitly checkout the repo.

To publish a pipeline artifact add the Publish Pipeline Artifact as task in your Build stage. In your Deploy stage you can then reference files in that artifact with the path $(Pipeline.Workspace)/<artifactName>/<rest-of-path>

To checkout out the whole repo add this to your Deploy stage:

steps:
- checkout: self
  path: 'myrepo/'

Then reference the files in the repo using $(System.DefaultWorkingDirectory)\<rest-of-path>

Upvotes: 6

Related Questions