Script path of PowerShell task Azure DevOps release - azure

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.

Related

Azure devops - How to use same yml for multiple git repos

I use github for hosting my projects and have multiple projects in github. And I use Azure devops for CICD alone. I have a single project in Azure devops, where I create individual pipeline corresponding to each project in my github repo. All these github projects would need to use the same azure-pipeline.yml for build. So instead of keeping the same yml file in each project, is there a way I can keep this yml centrally. So that in future, if at all a change is required, I need not do it for all individual projects, instead, update the main yml template.
A single yml file where I have all the code is even possible for my usecase? Any help is much appreciated
Have you considered using templates? Essentially you have would end up with a single template containing the main build steps that is reusable and individual yaml for each pipeline that can pass parameters to the template for any differences you have between them (such as different triggers or variable values). This way you can update all pipelines by making changes to the template
Template documentation
According to your description, you may setup a repo contains all the YAML files for pipelines. Kindly also be advised that we can also keep the templates in other repositories, if we have defined the repository resources in the core YAML pipeline. Kindly refer to the sample Core and template YAML files below.
#Core YAML in Azure Repos
trigger: none
pool:
  vmImage: ubuntu-latest
resources:
  repositories:
  - repository: GitHub_REPO_1
    type: github
    name: GitHubAccountName/GitHubRepo1
    endpoint: GitHubServiceConnectionName
  - repository: GitHub_REPO_2
    type: github
    name: GitHubAccountName/GitHubRepo2
    endpoint: GitHubServiceConnectionName
steps:
  - checkout: none
  # - checkout: GitHub_REPO_1
  - template: GHREPO1.yml#GitHub_REPO_1
  # - checkout: GitHub_REPO_2
  - template: GHREPO2.yml#GitHub_REPO_2
#Template YAML from GitHub Repo
steps:
- script: echo "This YAML template is from GitHubRepo1"
  displayName: 'Template From GitHubRepo1'
By the way, we could also checkout the code from one or multiple repository resource(s) and trigger the pipeline by the commits from the repository resources. Please refer to the following documents for more information.
Define YAML resources for Azure Pipelines - Azure Pipelines | Microsoft Docs
Check out multiple repositories in your pipeline - Azure Pipelines | Microsoft Docs

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).

Azure DevOps - Automated Pipeline Creation

I'm new to Azure DevOps, and I was wondering if there was a way to automatically detected a .yml build file and create a pipeline without having to interact with the site.
I have tried creating a file called azure-pipelines.yml in the root of the repo, with no luck.
Is there anyway to automatically create pipelines? Like how Jenkins detects a Jenkinsfile?
No this is nott possible out of the box, because YAML file is not always pipeline definition. You my try to figure out if it is trully is, however you need to listen for repo changes and in fact you can do this via another pipeline ;) for instance as this:
check if commit has a new yaml file added
verify if the file is pipeline
create a pipeline using azure cli (for instance)
However, this would be quite a lot of work and then you need to create such pipeline in every repo you want to have this detection enabled.

ARM template link to refactor template values

Summary: We have Below mentioned release pipelines
1. Release1 -This pipeline will create resources like Application insights, App service plan, Key vault. (ARM files -azuredeploy.json and azuredeployparameters.json)
2. Release2 Pipeline: This pipeline will create resources like App service/Function App using Release1 components like Application insights, App service plan, Key vault. (ARM files -azuredeploy.json and azuredeployparameters.json)
We have multiple micro services In Release2 pipelines,
Environments like Dev, QA, Test .
Each environment has separate resource group.
azuredeployparameters.json all values are same for all services except webapp name.
Issue:If we want change or update any value in all azuredeployparameters.json files in all Release2 pipeline services, We are updating manually.
Kindly suggest the solution on below:
Can we link all our release2 azuredeployparameters.json files to one centralized azuredeployparameters.json file.
If we modify centralized azuredeployparameters.json file, it should update all azuredeployparameters.json files in all release 2 services.
You can put your azuredeployparameters.json in your central/main repo. And if you use release pipelines for instance, you should create build for your central repo and publish azuredeployparameters.json as artifact. You can later use this artifacts in any release pipeline you want. So you can get it Release1 and Release2.
If you use build pipelines also to deploy, you can use multiple repos and get source code (in release 1) from your central repo and repo dedicated to this release. In the same way you have this file available.
If you want to customize file a bit in Relese pipeline you can tokenize you azuredeployparameters.json file and replace those tokens in release. Here you have extension for this.

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
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.

Resources