7

So I am attempting to create a downstream project trying to use an artifact stored in azure pipeline artifact to build. I am using the task DownloadPipelineArtifact@0

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/download-pipeline-artifact?view=azure-devops

It talks about the need for a pipelineId, not really sure where to find out the id for my other pipeline. Is there any easy way, its supposed to be a ~4 digit number according the documentation.

Thanks

sandeepzgk
  • 511
  • 2
  • 6
  • 16
  • 1
    The documentation on https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&viewFallbackFrom=vsts states that the System.DefinitionId is The ID of the build pipeline. but that id is not working as expected. – sandeepzgk Feb 06 '19 at 22:10

6 Answers6

10

Go to the target pipeline you want -> Edit.

Check the URL. There you have the pipeline id.

.../_apps/hub/ms.vss-build-web.ci-designer-hub?pipelineId=1234&branch=main

I'm sorry I could not find a proper way to refer this without hardcoding.

Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63
4

You can get pipeline ID from a pipeline directly from portal.

  1. Go Azure Pipeline

    enter image description here

  2. Now select the pipeline you want the ID from and choose “Edit”

enter image description here

  1. Once in EDIT PIPELINE mode, click the dotted menu and select “TRIGGERS”

enter image description here

  1. Now, click on “variables” tab

enter image description here

  1. Here you will see a variable — system.definitionId which is aka PipelineId

enter image description here

Zee A
  • 83
  • 5
  • 2
    you are correct, https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/download-pipeline-artifact-v2?view=azure-pipelines#how-can-i-find-the-id-of-the-pipeline-i-want-to-download-an-artifact-from – 24x7Cloud Services Jan 02 '23 at 10:16
2

There is an existing open issues on the pipeline ID.

The doc which you mentioned doesn't provide much information about pipelineID.

As per microsoft

pipelineId appears to be BuildId, and not the build definition id. It needs the actual instance id of where the artifact is associated. I was able to make this work by referencing a release variable tied to the artifact alias. My alias is named "artifacts" and using $(RELEASE_ARTIFACTS_ARTIFACTS_BUILDID) did the trick. So the format would be $(RELEASE_ARTIFACTS_<alias>_BUILDID)

If you were trying to consume in a build and not a release pipeline you would need to somehow get the value of $(Build.BuildId)

I hope as this matures there are plans to make pipeline artifacts published from a build automatically in release, just like they are when using the old Build Artifacts. Currently for me that is not happening so I am forced to manually add this step to my release pipeline and associate it with the build pipeline.

Jayendran
  • 9,638
  • 8
  • 60
  • 103
2

There are two IDs you may need to know in Azure Pipelines.

  1. Build Pipeline ID / Definition ID: This is the ID of the Pipeline not a particular run of the pipeline. You can get it via System.DefinitionId

  2. Build Record ID / Build ID: This is the ID for a particular run/record of your pipeline run. You can access it in your pipeline as Build.BuildId

In your case, you will need to use the Build.BuildId since you are trying to get the artifact from a particular run of a pipeline.

Reference: Predefined Azure Pipeline Variables

Abdul-Razak Adam
  • 1,070
  • 11
  • 19
1

I was facing the same problem in my azure devops pipelines, I don't know if it applies the same way for you, but here is my solution to do it :

There is the function az pipeline show that gives you the id of a pipeline with its name:

Pipeline_to_find="$1"
pipelineInfo=$(az pipelines show --name "$Pipeline_to_find")
id=$(echo "$pipelineInfo" | python -c "import sys, json; print(json.load(sys.stdin)['id'])")
#export this var to be used in any other task of your pipeline
echo "##vso[task.setvariable variable=id;]$id"
ultimatom
  • 11
  • 1
0

The following command uses Azure CLI (with DevOps extension) and jq to get the pipeline id in Bash shell:

az pipelines show --name <PIPELINE_NAME> | jq -r .id

If you want to use this inside an Azure Pipeline, you need to use an Azure CLI task and probably install jq on the run agent.

See ultimatom's answer for how to set the id as a variable in the pipeline.

Lazer
  • 501
  • 4
  • 14