How to create single pipeline(s) for all projects in an organization - azure-devops

I have more than 35 projects in an organization in Azure DevOps. These are the solutions of a Single product. Right now I am creating build and release pipelines for each project one by one.
If I create a pipeline for a single project and release the build, I want devops to create pipeline & releases builds for all the other projects(in the same organization) together at once.
For eg, There are projects A,B,C & D. If I create a release pipeline for Project A, will Devops automatically Release build for other projects "B,C & D" in the same organization at the same time.
We need to avoid creating pipelines for each projects one by one. Is this possible and is there any scripting or configuration to achieve this?
Thanks in Advance.

The process of setting up multiple release definitions with the exact same tasks can be very time consuming and difficult to manage -- fortunately, our team solved this problem using Task Groups!
Task Groups allow you to bundle multiple steps into a single "group", parameterize them, and then invoke them like a single step. You can also edit the Task Group at any time which will cascade to all places where it's used.
The other consideration is that you can bundle your custom variables into Variable Groups and reuse them between Release Definitions. Having your configuration reusable also has the benefit of only having to edit a single item.
I'd recommend:
Create a single release definition as a golden reference example.
Add your build steps for a single stage/environment
Once you're happy with this release definition, multi-select the steps you want to bundle into a group, open the context menu and select the option to convert to a Task Group. This will remove the steps from your release and move them to the Task Group.
Customize the Task Group with the appropriate parameters and then save it.
Modify your release definition to use the Task group parameters.
Add the additional stages to your environment, and add your custom Task Group to each parameterizing with configuration specific to the environment.
Once you're happy with the Release Definition -- use the Clone feature to create 34 more instances.
The same approach can be applied to builds.

Related

How to run the same Azure DevOps pipeline with different library variables - without cloning?

I have a reasonably complex release pipeline in Azure DevOps that releases a number of Azure apps, a database etc.
Each step is genericised using a library variable for the environment. For example:
But library variables are linked to a release or a selection of stages.
Currently I have to clone the entire pipeline and link a new library variable group in the clone to publish a different environment, but this is heavy on unwanted duplication and maintenance.
How can I run the same release pipeline with different library variables?
If I could do this, it would be possible to have a release for a given branch, for example, but I cannot see a way to do it.
At of this time, it is not supported to select which variable groups to use when you create a release.
If you only have one or several variables, I think you can use pipeline variables instead of variable groups, so that you can update them at release time. Here are the detailed steps:
Go to your pipeline editing page and select "Variables" tab. Click "Add" to add a variable. Then check the option "Settable at release time".
Try re-create your release. You will find the variables defined in #1 and you can edit them before create the release.
If you have many variables, I suggest you try to change the structure of your pipeline to make it more suitable for deployment to multiple environments. As Daniel said, you can use stages for each environment, and then use the variable group in stages scope.

How can we add calculated custom fields on a process in Azure Devops Boards

How can we add calculated custom fields on a process in Azure DevOps Boards. Is there any extensions that can be used for creating a Calculated custom field?
Azure DevOps support rollups in the backlogs only: Display rollup progress or totals.
To use your own logic, you can:
Create an extension (for example WSJF (Weighted Shortest Job First)).
Use az boards work-item to get, calculate, and update fields.
Use Excel to create calculated columns and publish fields: Bulk add or modify work items with Excel
If you mean creating a custom field Calculated to your project process. You can follow below steps.
1, Go to organization settings -->Process-->Select the process which your project is currently using.
If your project is using the System processes: Agile, Basic, Scrum, and CMMI. You need to create Inherited processes. For System processes are locked from being changed. See System versus inherited processes.
After you select your project process. You can select work item types to add the custom field. See Add a custom field.
2, If your project was using System processes. After you created the Inherited process, and added the custom field. You need to change your project process to this newly created inherited process. See Change the project process.

Share variables across build pipelines in Azure devops

I have 2 build pipelines in my azure devops project, one for building source code and the other one is for
making the setup.
I want the build number generated by the first pipeline that compiles code to be passed to the next pipeline which creates the setup file because i want the setup file to take the same version, so I added a variable group with a variable called sharedBuildCounter.
But when I set sharedBuildCounter the build number in the first pipeline using logging command like this(used inside PowerShell task):
Write-Host "##vso[task.setvariable variable=variable_name;]new_value"
The variable indeed takes the new value and I am able to output the new value using another PowerShell task with one line:
Write-Host $(SharedBuildCounter)
And when I run the next pipeline that builds the setup, I find that sharedBuildCounter is being re-set to the default empty value.
Notice: I found threads that suggests using API rest calls to change variable values, but it don't seem to include a specific pipeline name in case of using pipeline variables(not variable groups).
Variable groups will help to share static values across builds and releases pipeline.
What you need is a way to pass variables from one pipeline to another. I'm afraid to say the is no official way to do this.
As a workaround you could update the value of your variables inside your variable group. There are multiple ways to handle this, Rest API, powershell, 3rd-party extension. Detail ways please refer answers in this question: How to Increase/Update Variable Group value using Azure Devops Build Definition?
If you want to get the value of variable in the pipeline. Since you have used logging command to update that variable.
You need to use Rest API to get that particular build log to fetch related info.
You can use Azure Artifacts to pass information between pipelines. In one pipeline, you write the values to a file and publish the file to an artifact. In the other pipeline, you download the artifact and read the file.
There may be other ways to do it. Azure DevOps allows for free and infinite use of Azure Artifacts in this fashion.
See How to get variable values from pipeline resources in azure pipelines.

How to manage PR validation builds for 100+ projects

We have 100+ services/apps in a repository in Azure Devops. We have defined a single CI/CD YAML multistage pipeline for each (build and deployment). This limits blast radius and allows for auditability of each release of each project. We rely on templates for all the real pipeline work so this is easy to maintain; just a small root azure-pipelines.yml file for each project that includes the needed templates.
Now, we'd like to start using PR validation builds. And, as best as I can tell, we have two options:
Create a separate PR build for for every project and use the UI/API for policies to create 100+ policies
Create a single PR build that has stages for all 100+ projects.
I'm not a fan of the 1st option as now we'll have 200+ builds. The 2nd option is possible, but to avoid a 3 hour PR build, we'd need a way to only run needed stages (aka project builds).
Is there a 3rd option I'm missing? If the 2nd option is our best bet, how do we turn off stages for projects not changed in that PR (i.e. what condition would we use)?
(FYI, our policy is to change only one project per PR, but there are, on occasion exceptions to that.)
For personal suggestion, I also recommend the second method. Though the build script would be very large in one configure file, but much better than have hundreds build configuration files.
But the difficulty is these 100+ apps are all in one repository. This means all the normal method will not suitable for you, include using Build.Repository.Name value as the stage condition. Also, there's no more details which describing the source file path stored in the commit.
So, I suggest you and your team developers input the project name info into your commit message. Then, in the build pipeline you could use the variable Build.SourceVersionMessage to get its comment message. Since this is a environment variable which only work in step level(Not work for stage level and the job level), it needs you add one task in the first step and use the condition for it.
The logic of it is add one step as the first one in every stages. This step is only used to conditional judgment. If the Build.SourceVersionMessage matches the prefix or any key contents words, the jobs will be early-exit.
If use the condition like this:
condition: startsWith(variables['Build.SourceVersionMessage'], '[maven-plugin]')
It needs your commit message must follow a strict content writing format, starting with the specified project name.
Another condition can for you consider is:
condition: in(variables['Build.SourceVersionMessage'], 'maven-plugin')
This does not need the strict content writing format, but also need input the project name in the commit message. Thus it could be evaluated in the job condition with the above script.
Hope it could give you some help.

Is it possible to have shared tasks for different environments (stages) on VSTS?

I have release pipeline in VSTS that has four stages. Dev, Test, Pre-Prod and Prod. These stages share the same steps and the only difference are the variable values that change depending of the stage.
At the moment if I add a new step I have to add it on the four stages even if it is the same and the only difference is the value of the variables.
Is it possible to have a shared stage that is used by my four environments where the only difference would be the variables. This is to prevent having to add the same step four times
Use task groups. Task groups allow you to define a set of build/release steps and reuse them across different builds, releases, and release environments.