sandeepzgk
sandeepzgk

Reputation: 561

How do i identify my AzureDevOps id for a pipeline in ADO Pipelines?

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

Upvotes: 12

Views: 34562

Answers (6)

Abdul-Razak Adam
Abdul-Razak Adam

Reputation: 1128

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

Upvotes: 4

Zee A
Zee A

Reputation: 141

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

Upvotes: 9

Lazer
Lazer

Reputation: 581

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.

Upvotes: 1

ultimatom
ultimatom

Reputation: 11

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"

Upvotes: 1

Ε Г И І И О
Ε Г И І И О

Reputation: 12321

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.

Upvotes: 12

Jayendran
Jayendran

Reputation: 10910

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.

Upvotes: 2

Related Questions