Ask Your Question
3

How can one run multiple tasks simultaneously in a single job within a pipeline using Azure Pipelines?

asked 2023-05-30 01:18:38 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-30 01:48:01 +0000

bukephalos gravatar image

Azure Pipelines allows running multiple tasks simultaneously within a single job by defining multiple parallel jobs in the pipeline. These jobs can run in parallel on different agents or on the same agent using multiple threads. To define parallel jobs, follow these steps:

  1. Define a job with a unique name using the jobs keyword.
  2. Define multiple tasks within the job.
  3. Add a strategy section within the job definition to define the number of parallel jobs, and the pool of agents to use for executing these jobs.
  4. Optionally, define dependencies between tasks to ensure that they are executed in the correct order.

Here's an example YAML definition for running two tasks in parallel:

jobs:
- job: ParallelJob
  pool:
    vmImage: 'ubuntu-latest'
  strategy:
    matrix:
      python:
        - '3.6'
        - '3.7'
      node:
        - '10.x'
        - '12.x'
  steps:
  - task: PythonTask
    displayName: 'Run Python Tests'
    inputs:
      versionSpec: '$(python)'
  - task: NodeTask
    displayName: 'Run Node Tests'
    inputs:
      versionSpec: '$(node)'
  - task: PublishTestResults@2
    displayName: 'Publish Test Results'
    inputs:
      testResultsFormat: 'JUnit'
      testResultsFiles: '**/TEST-*.xml'

In this example, two parallel jobs are defined based on the matrix strategy for Python and Node.js versions. The PythonTask and NodeTask are executed in parallel on the specified agents, and the results are published using the PublishTestResults task.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-30 01:18:38 +0000

Seen: 7 times

Last updated: May 30 '23