Search code examples
azure-devopsazure-pipelinesazure-pipelines-yaml

Passing artifacts between pipelines


The DependantPipeline (which is triggered by the another pipeline: MainPipeline) causes errors on Azure DevOps:

Download Pipeline artifact Starting: Download Pipeline artifact Download from the specified build: #178678 Download artifact to: /agent/_work/64/Pipeline ##[error]Artifact Pipeline was not found for build 178678. Finishing: Download Pipeline artifact

I tried to trace the file which is responsible to download artifacts in my repo, however by title I cant find it Download Pipeline artifact. Does it mean someone does not use displayName parameter and it takes that by default? Or would you give me any hint how to navigate/track files based on the output from Azure DevOps? So far by the the name works for me, not this time.

However, I found those files, which seems to be related with publishing/downloading, I hope:

take_templates.yml

steps:
  - task: DownloadPipelineArtifact@2
    displayName: "Templates from DEV"
    inputs:
      artifact: "Pipelines"
      buildType: "current"
      targetPath: "$(Pipeline.Workspace)/Pipelines"

deployment.yml

parameters:
  - name: pipelineOptions
    type: object
  - name: environment
    type: string

jobs:
  - deployment: Initializing
    displayName: "Initializing"
    environment: ${{parameters.environment}}
    strategy:
      runOnce:
        deploy:
          steps:
            - template: take_templates.yml
            - ${{ if eq(parameters.pipelineOptions.isDetectChangesEnabled, 'true') }}:
              - template: ./take_changes.yml

take_changes.yml

steps:
  - download: current
    displayName: "DetectChanges"
    artifact: DetectChanges
  - task: PowerShell@2
    displayName: "Publish Changes"
    name: "DetectChanges"
    inputs:
      targetType: "FilePath"
      filePath: take_changes.ps1
      arguments: -inputFileName './changes.json'

Currently, I have a pipeline (MainPipeline) which triggers another one (DependantPipeline), which in turns should make a deployment based on the changes, and take (as I believe) uploaded artifacts in the previous pipeline: MainPipeline, to the triggered pipeline: DependantPipeline.

EDIT 1.

I tried different combinations to stick this together based on the articles, however no no no I cant complete this

Dependant pipeline definition:

trigger: none

resources:
  repositories:
    - repository: Pipelines
      type: git
      name: Pipelines
      ref: test/pipeline
  pipelines:
    - pipeline: SourcePipeline
      project: DEV
      source: 'dev-main'
      trigger:
        branches:
          include:
                - test/pipeline
# the rest of code goes here

Solution

  • Based on the update where additional YAML templates were shared, we could see

    1. The DownloadPipelineArtifact@2 pipeline task with the displayName: "Download Templates from DEV" in take_templates.yml was defined to download the artifacts called Pipelines, which should be published during the current build due to buildType: "current", so that it could be consumed;
    2. Another download pipeline task with NO displayName property in take_changes.yml was defined to download the artifacts called DetectChanges, which should be also published during the current build due to download: current;

    However, neither of the two tasks seemed to incur this error, as the message ##[error]Artifact Pipeline was not found indicated that it was downloading artifacts called Pipeline, NOT Pipelines or DetectChanges.

    For this, I am afraid you will need to check if there was any other DownloadPipelineArtifact@2 or download task that was defined to consume the artifacts called Pipeline without a displayName, which should be the one affected.

    Image

    In addition, we did notice the PublishPipelineArtifact@0 task in init.yml published the artifacts called Pipelines. Let's assume init.yml was from the MainPipeline (dev-main), and you would expect to download the artifacts Pipelines during the downstream DependentPipeline.

    If that was the case, the DependentPipeline should not use DownloadPipelineArtifact@2 buildType: "current" but use download: SourcePipeline instead. (SourcePipeline was the symbolic name of your pipeline resource dev-main as defined in your Dependent pipeline definition).

    # Dependent pipeline definition
    
    trigger: none
    
    resources:
      pipelines:
        - pipeline: SourcePipeline
          project: DEV
          source: 'dev-main'
          trigger:
            branches:
              include:
                - test/pipeline
    
    steps:
      # - task: DownloadPipelineArtifact@2
      #   displayName: "Download Templates from DEV"
      #   inputs:
      #     artifact: "Pipelines"
      #     buildType: "current"
      #     targetPath: "$(Pipeline.Workspace)/Pipelines"
    
      - download: SourcePipeline
        artifact: "Pipelines"
        displayName: "Download Templates from DEV"