Creating Multiple Jobs
Ankit Ranjan (DevOps Engineer)
Actively Seeking Azure DevOps/Cloud Role | DevOps Engineer | Automating & Reducing Developer Toil | Modernising IAC like Jam on the Bread | Microsoft Certified: Azure Admin Associate | Certified Terraform Associate |
In the previous post, we talked about Creating Tasks. Today we will talk about the steps in creating multiple jobs.
When setting up a build pipeline for an application that needs to be built for multiple operating systems simultaneously, you often need to add an additional job to handle this. There are two types of jobs you can create: agent jobs and agentless jobs.
An agent job runs on an agent or target computer, while an agentless job runs directly on the Azure DevOps application server. Here are the steps to create additional agent jobs in a build pipeline:
1. Edit the build pipeline by clicking the ... symbol and selecting Edit:
2. Click on the ... button and select Add an agent job:
3. Click on Agent job and update the job information as follows:
Display name: Agent job 2
Agent pool: Azure Pipelines
Agent Specification: ubuntu-latest
4. Click on the + button for the job, type the Command line in the search box, and then click the Add button:
5. Click on the row with the Command Line Task and update the following fields:
Task version: This is a package version of the Command Line Task. We usually use the latest version. In our case, this is version 2.
Display name: Add a suitable name for your task. In our case, this is the Second Command Line Task.
Script: Add the following basic script – echo "Hello Second Task on Linux".
This will print out this text on the resultant page after you have finished running a pipeline:
6. After you click Save & queue, you will see the following result:
Let’s look at some of the advanced options available in the Agent job properties, as shown in the following Picture:
Let’s look at these options in some detail:
领英推荐
Agent selection:
Agent Pool: Choose either a custom or default agent to execute the build jobs.
Demands: Specify condition parameters to ensure that only agents meeting these conditions can run the agent job. For instance, you can set it so that only a Linux agent is allowed to run this job.
Execution Plan:
Parallelism Options:
- None: No jobs will run in parallel.
- Multi-configuration: Enable this when you need different configurations for each agent job. For instance, if you need to run tests on three browsers, you will need Chrome, Edge, and Firefox.
- Multi-agent: Enable this when you have multiple agents and need to use them to run an agent job.
Timeout: Enter the number of minutes an agent job is allowed to execute before being canceled.
Job Cancel Timeout: Enter the number of minutes an agent job can run after receiving a cancel request before it is forcibly stopped.
Dependencies: You can select a previous agent job that must complete successfully before running another agent job.
Additional Options:
- Allow scripts to access the OAuth token: Enable this if you need to use the OAuth token to pass information to another agent job via REST API.
Run This Job:
- Only when all previous jobs have succeeded
- Even if a previous job has failed
- Only when a previous job has failed
- Custom condition using variable expressions: For example, succeeded() means the agent job will run if the previous one is completed successfully.
In this section, you learned how to create a second job to separate the Linux operating system. This allows two jobs to run simultaneously, which is useful for running tasks on different operating systems independently. For example, you can create a build pipeline that deploys your application to both Google Play and the Apple Store simultaneously without sequential execution.
In our upcoming post, we'll explore how to create a trigger to automatically run a build pipeline.
Microsoft Learn Microsoft Azure Microsoft Azure DevOps