0
votes

The deployment job automatically downloads all the pipeline resources. However, standard job does not. I tried to use - download: current, but that does not download the pipeline resources.

The reason I want to do this is to simulate a deployment for GitOps. The simulation will include a step that does a git diff that shows the differences for review.

However, I don't see an all or * option in https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#download

My current workaround is to do a deployment to a "Temp" environment prior to the real deployment.

UPDATE: Here's an example of what I have tried

resources:
  pipelines:
    - pipeline: auth
      project: myproj
      source: auth CI
      trigger:
        branches:
          include:
            - master
...
    jobs:
      - job: diagnostics
        displayName: Job Diagnostics
        steps:
          - checkout: self
          # - download: 
          - task: DownloadPipelineArtifact@2
            displayName: 'Download Pipeline Artifact'
            inputs:
              path: $(Build.SourcesDirectory)
          - bash: |
              env | sort
            displayName: Display environment variables
          - bash: |
              pwd
            displayName: Present working directory
          - bash: |
              find $(Pipeline.Workspace) -type f -print
            displayName: Display files

UPDATE: Another approach I was mulling is to create a pipeline that creates another pipeline. That way the list of pipeline resources does not need to be Azure Pipeline YAML, it could be a CSV or a simplified YAML that I transform in which case I can generate

resources:
  pipelines:
    - pipeline: pipelineAlias1
      project: myproj
      source: auth CI
      branch: master
      trigger:
        branches:
          include:
            - master

    - pipeline: pipelineAlias2
      project: myproj
      source: auth CI
      branch: master
      trigger:
        branches:
          include:
            - master
...
job:
  steps:
   - download: pipelineAlias1
   - download: pipelineAlias2

and then set that up as another Azure pipeline to execute when updated.

1

1 Answers

-1
votes

How do you download all pipeline resources in a job?

Indeed, this is a known issue about using the download keyword to download the Pipeline Artifacts.

You could track this issue from below ticket:

Artifacts do not download on multi stage yaml build using DownloadPipelineArtifactV2

To resolve this issue, please try to use the DownloadPipelineArtifact task instead of the download keyword:

  - task: DownloadPipelineArtifact@2

    displayName: 'Download Pipeline Artifact'
    inputs:
      path: $(Build.SourcesDirectory)

Update:

I have noticed your yml file, it seems you do not add build job in your pipeline. The task DownloadPipelineArtifact is used to:

download pipeline artifacts from earlier stages in this pipeline, or from another pipeline

So, we need to add stage to build the pipeline to generate the artifact, otherwise, no pipeline artifacts were downloaded.

Check my test YAML file:

variables:
  ArtifactName: drop

stages:
- stage: Build
  jobs:
  - job: Build
    displayName: Build
    pool:
     name: MyPrivateAgent
    steps:
      - task: CopyFiles@2
        displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)\LibmanTest'
          targetFolder: '$(build.artifactstagingdirectory)'
      - task: PublishBuildArtifacts@1
        displayName: 'Publish Artifact: LibmanTest'
        inputs:
          ArtifactName: $(ArtifactName)


- stage: Dev
  dependsOn: Build
  jobs:
  - job: Dev
    displayName: Dev
    pool:
     name: MyPrivateAgent
    steps:
      - task: CopyFiles@2
        displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)\TestSample'
          targetFolder: '$(build.artifactstagingdirectory)'
      - task: PublishBuildArtifacts@1
        displayName: 'Publish Artifact: TestSample'
        inputs:
          ArtifactName: $(ArtifactName)


- stage: Deployment
  dependsOn: Dev  
  pool:
    name: MyPrivateAgent
  jobs:
  - deployment: Deployment
    displayName: DeployA
    environment: 7-1-0
    strategy:
      runOnce:
        deploy:
          steps:

          - task: DownloadPipelineArtifact@2

            displayName: 'Download Pipeline Artifact'
            inputs:
              path: $(Build.SourcesDirectory)

As you can see, I use two stages Build and Dev to copy the project LibmanTest and TestSample as artifact, then use the task DownloadPipelineArtifact to download those two artifacts.

The test result:

enter image description here

Update2:

your example still does not show resources.pripelines

So, now you want to download the artifact from other pipelines, you need not use the default configuration for the task DownloadPipelineArtifact:

resources:
  pipelines:
    - pipeline: xxx
      project: MyTestProject
      source: xxx
      trigger:
        branches:
          include:
            - master

  jobs:
  - deployment: Deployment
    displayName: DeployA
    environment: 7-1-0
    strategy:
      runOnce:
        deploy:
          steps:
          - task: DownloadPipelineArtifact@2
            displayName: 'Download Pipeline Artifact For Test'
            inputs:
              buildType: specific
              project: MyTestProject
              definition: 13

The test result:

enter image description here

Besides, you could check the configuration from the classic editor, then get the YAML file:

enter image description here

Hope this hellps.