Download artifact from Azure DevOps Pipeline grandparent Pipeline

Download artifact from Azure DevOps Pipeline grandparent Pipeline

azure devops download build artifacts
azure devops release pipeline multiple artifacts
pipeline artifacts
azure devops multi stage pipelines artifacts
publish build artifacts
azure devops artifacts
could not find any pipeline artifacts in the build.
azure devops combine artifacts

Given 3 Azure DevOps Pipelines (more may exist), as follows:

  1. Build, Unit Test, Publish Artifacts
  2. Deploy Staging, Integration Test
  3. Deploy Production, Smoke Test

How can I ensure Pipeline 3 downloads the specific artifacts published in Pipeline 1?

The challenge as I see it is that the Task DownloadPipelineArtifact@2 only offers a means to do this if the artifact came from the immediately preceding pipeline. By using the following Pipeline task:

- task: DownloadPipelineArtifact@2
  inputs:
    buildType: 'specific'
    project: '$(System.TeamProjectId)'
    definition: 1
    specificBuildWithTriggering: true
    buildVersionToDownload: 'latest'
    artifactName: 'example.zip'

This works fine for a parent "triggering pipeline", but not a grandparent. Instead it returns the error message:

Artifact example.zip was not found for build nnn.

where nnn is the run ID of the immediate predecessor, as though I had specified pipelineId: $(Build.TriggeredBy.BuildId). Effectively, Pipeline 3 attempts to retrieve the Pipeline 1 artifact from Pipeline 2. It would be nice if that definition: 1 line did something, but alas, it seems to do nothing when specificBuildWithTriggering: true is set.

Note that buildType: 'latest' isn't safe; it appears it permits publishing an untested artifact, if emitted from Pipeline 1 while Pipeline 2 is running.

There may be no way to accomplish this with the DownloadPipelineArtifact@2. It's hard to be sure because the documentation doesn't have much detail. Perhaps there's another reasonable way to accomplish this... I suppose publishing another copy of the artifact at each of the intervening pipelines, even the ones that don't use it, is one way, but not very reasonable. We could eliminate the ugly aspect of creating copies of the binaries, by instead publishing an artifact with the BuildId recorded in it, but we'd still have to retrieve it and republish it from every pipeline.

If there is a way to identify the original CI trigger, e.g. find the hash of the initiating GIT commit, I could use that to name and refer to the artifacts. Does Build.SourceVersion remain constant between triggered builds? Any other "Initiating ID" would work equally well.

You are welcome to comment on the example pipeline scenario, as I'm actually currently using it, but it isn't the point of my question. I think this problem is broadly applicable, as it will apply when building dependent packages, or for any other reasons for which "Triggers" are useful.


An MS representative suggested using REST for this. For example:

HTTP GET https://dev.azure.com/ORGNAME/PROJECTGUID/_apis/build/Builds/2536

-

{
    "id": 2536,
    "definition": {
        "id": 17
    },
    "triggeredByBuild": {
        "id": 2535,
        "definition": {
            "id": 10
        }
    }
}

By walking the parents, one could find the ancestor with the desired definition ID (e.g. 10). Then its run ID (e.g. 2535) could be used to download the artifact.

@merlin-liang-msft suggested a similar process for a different requirement from @sschmeck, and their answer has accompanying code.

Download Pipeline Artifacts task, Use this task to download pipeline artifacts from earlier stages in this pipeline, or from another pipeline. YAML snippet. YAML Copy. #  Download Pipeline Artifacts task. 01/23/2020; 3 minutes to read +10; In this article. Use this task to download pipeline artifacts from earlier stages in this pipeline, or from another pipeline.


There are extensions that allow you to do this, but the official solution it to use a multi-stage pipeline and not 3 independent pipelines.

Publish and consume artifacts in pipelines, Understand pipeline artifacts in Azure Pipelines and Azure DevOps Server. Publish and download artifacts. 05/04/2020; 7 minutes to read. The Download Pipeline Artifact task can download both build artifacts (published with the Publish Build Artifacts task) and pipeline artifacts. By default, files are downloaded to $ (Pipeline.Workspace)/ {artifact}, where artifact is the name of the artifact. The folder structure of the artifact is always preserved.


One way is using release pipelines (you can't code/edit it in YAML) but you can use the same artifacts through whole deployment.

Release pipeline

You can also specify required triggers to start deployment on

Approval and triggers

Alternatively, there exist multi-stage pipeline, that are in preview.(https://devblogs.microsoft.com/devops/whats-new-with-azure-pipelines/ ). You can access it by enabling it in your "preview feature".

Download Build Artifacts task, Download build artifacts # Download files that were saved as artifacts of a completed build - task: DownloadBuildArtifacts@0 inputs:  # Download build artifacts # Download files that were saved as artifacts of a completed build - task: DownloadBuildArtifacts@0 inputs: #buildType: 'current' # Options: current, specific #project: # Required when buildType == Specific #pipeline: # Required when buildType == Specific #specificBuildWithTriggering: false # Optional #


Multi-stage YAML Pipelines: Artifact Download Problem , Multi-stage YAML Pipelines: Artifact Download Problem? Closed - Not a Bug Azure DevOps · avatar image Timm Krause reported Jun  "Download build artifacts" task has the output variable BuildNumber that makes it possible to get the id of the build the artifact was downloaded from. The new "Download pipeline artifact" task (which is preferred over the "Download build artifacts") does not have any the output variables.


Unable to download build artifacts in release pipeline, Up until today, AzureDevops has worked pretty well for the Glowstone project. Today, we decided to set up code coverage (via jacoco) and got  Download a pipeline artifact. az pipelines runs artifact download --artifact-name--path--run-id [--detect {false, true}] Azure DevOps organization URL. You can


Please Release Me, Continuous Delivery, DevOps, ALM and IoT in a Mostly Microsoft Azure World. try and download an artifact created in a previous part of the pipeline. to do with the parent template and I decided it was probably a bad idea. From the pipeline run summary you can view the status of your run, both while it is running and when it is complete. From the summary pane you can download artifacts, and navigate to linked commits, test results, and work items. Cancel and re-run a pipeline. If the pipeline is running, you can cancel it by choosing Cancel.