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

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

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.

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.

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"

You can get pipeline ID from a pipeline directly from portal.
Go Azure Pipeline
Now select the pipeline you want the ID from and choose “Edit”
Once in EDIT PIPELINE mode, click the dotted menu and select “TRIGGERS”
Now, click on “variables” tab
Here you will see a variable — system.definitionId which is aka PipelineId

There are two IDs you may need to know in Azure Pipelines.
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
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

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.

Related

Tag version check between two pipelines azure devops

I have two CI pipelines in azure devops:
CI pipeline to train models
CI pipeline to score/predict/inference new data
Both of these pipelines are triggered when a PR is created on a specific branch. I have enabled "Tag Builds" on succeed with $build.BuildNumber format. I beleive if the builds are successful, they are given some tags.
I have a release pipeline, what I want to do is to check if the tag/buildNumber for 1st and 2nd CI pipelines are same or not. If not, the release pipeline should fail.
The problem is I cant find any tag information of the CI pipelines here is what I see after a build is succeeded.
I found out that. It is not possible to check if two or more tags are valid based on some logic in devops. So, we ended up using bash task and git commands to check if tags are valid (using regex).

Script path of PowerShell task Azure DevOps release

I have PowerShell script, that I would like to use in deployments of Dynamics 365 to migrate an Access Team Template to our Test and Prod environments.
I have added the PowerShell script to the repository, and I would now like to add a PowerShell task to each of the stages in the deployment to migrate the Access Team Teamplate correctly in each of the environments.
However, I am not sure how to reference the path of the script in each of the stages in the release. When I click on the three dots to select the file, it is looking at the Linked artifacts - and not the repo.
If I add the PowerShell task to the pipeline, then I can select the script from the three dots.
Is it possible to reference the script in the release somehow?
You need to add your repository as a artifact or publish this script as artifact in the pipeline.
First, use Add an artifact and select the repository where you keep the script:
Then you will get the repo as a regular artifact.
Another way is to publish this script. To do that you need to check the repo in the pipeline which you already have produce your primary artifact and publish just this script. Then it will become available as you already have a defined source of artifacts.

Is it possible to edit the YAML of a release pipeline?

I'm working on my first Azure DevOps Services release pipeline. I've got a secret in a variable group in the Azure DevOps | Library area. I've been struggling with getting to that secret so I can use it in the release pipeline. I see by this article Add & use variable groups on Microsoft's Docs that I must add that in the variables section of the YAML file. However, I've not seen any way to edit the release pipeline YAML file. I can view it, but there appears to be all. If there's a way of editing the YAML file, how do I get to it?
You should be able to do that, earlier To enable YAML release pipeline, you need to activate Multi-stage YAML pipelines in Preview features:
From the Docs,
To help make it even easier to edit and update your pipeline, we’ve
created an in-product editor with IntelliSense smart code completion,
and an easy task assistant
From the documentation you're pointing at.
If you're using YAML pipelines, you can reference the variable group in your YAML pipeline:
variables:
- group: my-variable-group
If you're using the classic mode, you can link the variable group to your pipeline through the UI:

Any possibility to automate the whole Azure pipelines creation using Azure Devops REST API? [duplicate]

This question already has an answer here:
How to create new build pipeline using Azure DevOps REST API?
(1 answer)
Closed 2 years ago.
I was looking for a solution of creating automation process for creation of pipelines to eliminate all the manual process we do while creating a pipeline in Azure devops portal.
Example:
If i want to deploy my Python based application and it doesn't have any pipelines defined previously. I want to create a pipeline and deploy the app to the Azure server whole process should be done with out manual intervention.
You still need to create somehow your YAML file or use what you have already. Of course you can prepare some templates and reuse them and if you define folder structure for your project and you will keep it then you will minimize yoour manual tasks. Once you have your YAML file defines you can use for instance az cli command:
az pipelines create --name 'Your pipeline name' --description 'Your pipeline description' --repository https://github.com/your-repo --branch master --yml-path your-file-in-repo.yaml --org https://dev.azure.com/your-organizaton --project 'your project'
From what I see this is not possible to use REST API to define YAML pipelines. Please take a look here.
So if you use calssic build it will be possible to use REST API. You can take a look here.
POST https://dev.azure.com/{organization}/{project}/_apis/build/definitions?definitionToCloneId={definitionToCloneId}&definitionToCloneRevision={definitionToCloneRevision}&api-version=5.1
You can for instance indicate here which definition should be cloned as a base for your new build.

How to I get the last run id for an azure pipeline?

I am writing an automated test suite using powershell and the az cli. I need to be able to download the build pipeline artefacts from the last run of the pipeline to install and test the application. The problem is I need to know the run ID to be able to download the artefacts.
az pipelines runs artifact download --artifact-name "*Artifact Name*" --run-id **nnn** --path "c:\temp"
Is there anyway to find the last successful run ID? At present I look it up through the GUI so I know the download works as long as you use PublishPipelineArtifact and not PublishBuildArtifact due to a bug in the az cli.
You can change how azure pipelines creates the run ID and use a predictable format. https://learn.microsoft.com/en-us/azure/devops/pipelines/process/run-number
One way is to use --output json then you can just iterate over the runs and look up the finishTime field:
az pipelines runs list --org $org --project $project --pipeline-ids $pipelineID --output json
I'm sure if you put in enough time there's probably a way using query strings to get latest as well.

Resources