skip to Main Content

I have a Azure DevOps pipeline where several stages run in parallel. One of those stages takes a lot longer to run than the others. Is there any way to make sure that specific stage is started first?

All of the options I found make other stages wait for this stage to finish. I do not want. The stages do not depend on each other.

The pipeline will just take less time overall if the slowest stage is started first. Is there a way to push it to the top of the queue?

2

Answers


  1. From Specify jobs in your pipeline:

    Azure Pipelines does not support job priority for YAML pipelines. To control when jobs run, you can specify conditions and dependencies.

    The only workaround I can think of is to add a dummy job to all the stages except the one that takes longer.

    Example:

    stages:
      - stage: A
        dependsOn: []
        jobs:
          - job: A1
            displayName: 'Long job A1'
            steps:
              - checkout: none
              - script: echo "A1"
      - stage: B
        dependsOn: []
        jobs:
          - job: B0
            displayName: 'Sleep job B0'
            steps:
              - checkout: none
              - script: sleep 1
          - job: B1
            dependsOn: B0
            displayName: 'Job B1'
            steps:
              - checkout: none
              - script: echo "B1"
      - stage: C
        dependsOn: []
        jobs:
          - job: C0
            displayName: 'Sleep Job C0'
            steps:
              - checkout: none
              - script: sleep 1
          - job: C1
            dependsOn: C0
            displayName: 'Job C1'
            steps:
              - checkout: none
              - script: echo "C1"
    

    When we run a new build all the jobs without dependencies will be added to the queue randomly – for example:

    1. Sleep job C0
    2. Long job A1
    3. Sleep job B0

    First 3 jobs

    Job B1 and Job C1 are not queued immediately because they depend on Sleep job B0 and Sleep job C0 respectively. They will be added to the queue and run at a later stage, but only after Long job A1 starts.

    Pipeline jobs

    Final order of the execution of jobs would be something like:

    1. Sleep job C0
    2. Long job A1
    3. Sleep job B0
    4. Job C1
    5. Job B0
    Login or Signup to reply.
  2. As the doc shared by @Rui Jarimba, Azure Pipelines does not support job priority for YAML pipelines.

    I would like to share another workaround for the requirement.

    You can split the stages into two pipelines. One pipeline is used to run the long time stage and the other pipeline is used to run other stages.

    You can trigger the pipeline (run long time stage) first, after the pipeline is running, you can trigger the another pipeline to run other stages.

    In this case, we can make sure that the long time stage can start first. And all stages still can run in parallel.

    If the stages contains multiple jobs, you can use the Run Next Option to increase the job priority.

    For example:

    enter image description here

    After clicking this option, the current job will be put to the top of the queue.

    Refer to this doc: Run this job next

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search