How to make and control of parallel execution of Azure DevOps Pipeline? - azure-devops

I am using Windows Self hosted agent for my Azure DevOps pipelines. Currently the pipelines are executed sequentially. If more than one pipelines triggered from different ADO projects, then it has to wait in queue to get the agent. In order to execute the pipeline in parallel, I came to know from some tutorials if we increase the paid parallel jobs for self hosted agent under billing section of Organization setting. Is my understanding correct? If so what are the precautionary steps I need to take. Do we have any control of when the pipelines to be executed in parallel?
Thanks.

In order to run self-hosted parallel jobs, you need to purchase parallel jobs and register several self-hosted agents.
For parallel jobs, you can register any number of self-hosted agents in your organization. If you want to run 3 jobs in parallel, then you must register at least 3 self-hosted agents in one agent pool. DevOps charges based on the number of jobs you want to run at a time, not the number of agents registered. There are no time limits on self-hosted jobs. For private projects, you can have one job and one additional job for each active Visual Studio Enterprise subscriber who is a member of your organization.
About how to purchase parallel jobs, please refer to Buy parallel jobs.
For how to control the use of parallel jobs, please refer to the following:
For classic pipeline, you can specify when to run the job through dependencies and Run this job in Additional options in the agent job. Then the pipeline will run in sequence according to your settings.
For YAML pipeline, you can specify the conditions under which the job should run with "dependsOn" and "condition".
For example:
For more info about conditions, please refer to Specify conditions
If you don't specify a specific order, the jobs will run in parallel based on the parallel jobs you purchased.

I don't know if my experience can help. I'll try. I started a new job and we use self-hosted TFS / Azure DevOps. I am changing our build process to create 3 product SKUs (it uses conditional compilation). Let's call them Good, Better & Best.
I edited the Build definition. First I switched to the Variables tab. I created a Process variable named SKUs and set it to Good,Better,Best. The commas are important.
Next I switched to the Tasks tab. I located the Agent Phase. Mine was called Phase 1. Select it. On the right, under Parallelism, I selected Multi-configuration. In the Multipliers text field I entered SKUs. I set Maximum number of agents to 3.
What I don't yet know is the TFS back-end administration and options that the company purchased beforehand.

Related

Is it possible in Azure DevOps Pipelines to wait for enough agents to run the job

We are running into the following issue:
We have a job in our pipeline that runs tests. The number of tests need to be distributed over 4 agents to run optimal. It can happen that only one agent is available and the job will start to run all the load on that specific agent, which can then time-out because it takes too long for other agents to become available in time to share in the load.
In essence, if we run with 4 agents, the job will run with optimal efficiency.
My question: is it possible to let a job wait for a specific number of agents to become available before starting the tasks in the job?
That`s not possible through out-of-box features.... But you may create a simple PowerShell script that will query your agents statuses: https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/agents/list?view=azure-devops-rest-7.1
and use includeAssignedRequest
GET https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolId}/agents?includeAssignedRequest={includeAssignedRequest}&api-version=7.1-preview.1
if you see assignedRequest, your build agent is busy...

Azure worker - Complete the release pipeline

I have a release pipeline composed of several stages
The tfs server have only one worker.
When i start a release, the worker run stages randomly.
The problem is : if someone else start another pipeline, sometimes the worker take the other pipeline before getting back to the next stage.
Is there a way to lock the worker on the entire release pipeline ?
When running a pipeline, a job is the unit of scale. This means each job can potentially run on a different agent.
Each job runs on an agent. A job represents an execution boundary of a set of steps. All of the steps run together on the same agent.
Next to that,
A stage is a logical boundary in the pipeline. It can be used to mark separation of concerns (for example, Build, QA, and production).
More information: Azure Pipelines - Key concepts.
You should also have a look at the Pipeline run sequence. It clearly explains how the entire pipeline-process works.
Whenever Azure Pipelines needs to run a job, it will ask the pool for an agent.
If the availability of the agent is the issue, you might want to add more agents to the pool. If needed, you can even run multiple agents on the same machine.
Although multiple agents can be installed per machine, we strongly suggest to only install one agent per machine. Installing two or more agents may adversely affect performance and the result of your pipelines.

Build agent metric in Azure Devops pipelines

We pay for a number of Microsoft hosted build agents in Azure pipelines. We have a lot of build pipelines, where many of them do jobs in parallel.
Are there any metrics I can use to see the utilization of the build agents and even more interesting, how many jobs are in queue for a free build agent?
Since this would be for the whole Azure Devops instance the Dashboard feature doesn't seems to be appropriate because it only seems to hold project specific metrics.
Got to your Organization Settings-Parallel jobs blade. This will give you the ability to view the jobs in progress.
As for metrics there is a public preview just came out for this; however, I do not have it available yet.
Agent pool usage data is sampled and aggregated by the Analytics service every 10 mins. The number of jobs is plotted based on the max number of running jobs for the specified interval of time.
This feature is enabled by default. To try it out, follow the guidance
below.
Within project settings, navigate to the pipelines “Agent pools” tab
From the agent pool, select a pool (e.g., Azure Pipelines) Within the
pool, select the “Analytics” tab

Azure devops- Running the multiple release from single release defnition

I am trying to invoke the multiple releases definition using REST API.Also enabled multiple agents for each Agent job. But even after triggering multiple releases the second release is in Queue and not at all starting. Is there any way to start the deployment parallelly from a single release defition.
Parallel jobs have different restrictions depending on the agents you use and your project is public or private.
Microsoft-hosted agent
If your jobs run on the pool of Microsoft-hosted agents. Microsoft provides a free tier of service by default in every organization:
Public project: 10 free Microsoft-hosted parallel jobs that can run
for up to 360 minutes (6 hours) each time, with no overall time limit
per month.
Private project: One free job that can run for up to 60 minutes each
time, until you've used 1,800 minutes (30 hours) per month.
Note:When you purchase your first Microsoft-hosted parallel job, the number of parallel jobs you have in the organization is still 1. To be able to run two jobs concurrently, you will need to purchase two parallel jobs if you are currently on the free tier. The first purchase only removes the time limits on the first job.
Self-hosted agent
To use self-hosted parallel jobs, you need to deploy self-hosted agents on your machines. You can register any number of these self-hosted agents in your organization. Microsoft charges based on the number of jobs you want to run at a time, not the number of agents registered.
Public project: Unlimited parallel jobs.
Private project: One self-hosted parallel job. Additionally, for each
active Visual Studio Enterprise subscriber who is a member of your
organization, you get one additional self-hosted parallel job.
For private project,when the free tier is no longer sufficient, you can pay for additional capacity per parallel job. Buy self-hosted parallel jobs.There are no time limits on self-hosted jobs.
These are stated in the document, you can refer to the link in Daniel's comment for details.

Azure-devops: Share output from different agents running their own jobs

I have a build with multiple jobs, where they depend on each other's output. But I also have multiple agents, which gives me the following issue:
If Agent1 runs Job1, Agent2 runs Job2, and Job3 requires the output from both Job1 and Job2, I can't access the files from just one agent, since they are located on different machines.
How do I make my jobs able to download the output of other agents?
I looked for the workspace on MS Docs, but it doesn't describe how to handle this scenario.
To add more details on top of JukkaK's answer.
I looked for the workspace on MS Docs, but it doesn't describe how to
handle this scenario.
The workspace is something corresponding to agents. No sure which kind of agent do you use, but different agents have different OS instance, so the content under same path(workspace) in one agent should be quite different from that in another agent.
So workspace is not the approach for you needs.
How do I make my jobs able to download the output of other agents?
You can use Publish Artifacts+Download Artifacts combination to do what you need. See this:
You can place Publish build Artifacts task as the last task of agent job1 and job2. Then add a Download buil Artifacts as the first one of agent job3.
And make sure agent job3 depends on agent job1 and job2 like this:
In this way, the output from agent job1 and job2 can be installed in agent job3's machine for further usage. Hope it helps.
Pipeline artifacts in multi-stage pipelines would be a perfect match for this, if the current features available with multi-stage pipelines otherwise satisfy your needs.
https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml
If not, the best I can come up with is directing the the jobs to same agent by adding a capability to agent and adding a demand to the pool-assignment (or by creating your own pool). With Deployment group agents, adding tags is a handy way to direct jobs to a certain agent in deployment group, but haven't found anything similar on build agents.
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/demands?view=azure-devops&tabs=yaml