3
votes

I have a complicated release that spans multiple deployment groups and I am planning to use the 3rd party vsts-git-release-tag extension to tag the release. Ideally, the entire release (all jobs) would succeed first before tagging the repository.

So I am trying to work out what the best way to accomplish that is. If this were a build pipeline rather than a deployment pipeline, it is clear I could just arrange them using dependsOn, as follows.

jobs:
- job: Deployment_Group_1
  steps:
  - script: echo hello from Deployment Group 1
- job: Deployment_Group_2
  steps:
  - script: echo hello from Deployment Group 2
- job: Tag_Repo
  steps:
  - script: echo this is where I would tag the Repo
  dependsOn:
  - Deployment_Group_1
  - Deployment_Group_2

However, there doesn't seem to be equivalent functionality (at least currently) in release pipelines as specified in this document.

Note

Running multiple jobs in parallel is supported only in build pipelines at present. It is not yet supported in release pipelines.

Although it doesn't specifically mention the dependsOn feature, there doesn't seem to be a way to utilize it in release pipelines (correct me if I am wrong).

I realize I could probably create a separate stage containing a single job and task to create the Git tag, but that feels like a hack. Is there a better way to run a specific release job after all other release jobs have completed?

3
Looks like a duplicate question stackoverflow.com/questions/29978758/…Klaus Heinrich
@KlausHeinrich - The linked question is about google cloud engine, this question is about azure pipelines. How is it a duplicate?NightOwl888

3 Answers

5
votes

Just a suggestion: you could make use of multistage pipelines which then are also very clearly represented in the Azure Devops Ui.

Stages have jobs, jobs have steps: enter image description here

Example pipeline yml for this:

trigger:
  batch: true
  branches:
    include:
      - "*"


resources:
  containers:
    - container: ubuntu
      image: ubuntu:18.04

stages:
  - stage: STAGE1
    jobs:
     - job: PrintInfoStage1Job1
       container: ubuntu
       steps:
          - script: |
              echo "THIS IS STAGE 1, JOB 1"
            displayName: "JOB 1"
     - job: PrintInfoStage1Job2
       dependsOn: PrintInfoStage1Job1
       container: ubuntu
       steps:
          - script: |
              echo "THIS IS STAGE 1, JOB 2"
            displayName: "JOB 2"

  - stage: STAGE2
    dependsOn: STAGE1
    jobs:
      - job: PrintInfoStage2Job1
        dependsOn: []
        container: ubuntu
        steps:
          - script: |
               echo "THIS IS THE STAGE 2, JOB 1"
            displayName: "JOB 1"

      - job: PrintInfoStage2Job2
        container: ubuntu
        dependsOn: []
        steps:
          - script: |
               echo "THIS IS THE STAGE 2, JOB 2"
            displayName: "JOB 2"

Just be sure to not miss switch on this preview feature on in your user's settings.

4
votes

After creating a test project and adding several jobs to a release pipeline for it, then running it several times in a row, it appears that the order of the jobs is deterministic. That is, they always seem to run in the order that they physically appear in the portal.

I did several Google searches, and this behavior doesn't seem be documented anywhere. So, I don't know for sure if it is guaranteed. But it will probably work for my case.

Please leave a comment if there are any official sources that confirm that the job order is guaranteed.

2
votes

Looking at the example that has been specified, you don't need to create different jobs for each of the steps. Every task could be added in a single job.

jobs:
- job: 
  steps:
  - script: echo hello from Deployment Group 1
  - script: echo hello from Deployment Group 2
  - script: echo this is where I would tag the Repo

You can also remove Jobs > Job in the code if you want.

I was facing a similar issue with my jobs not being exected in a defined order. Also, I was referencing other templates for jobs.I was under impression that every template has to be in a new job. Later, I managed to dissolve my jobs into tasks.

Points to note:

  • Job runs on a sperate agent. Which you might not want, if it is just a sequence of scripts that you want to execute. Job essentially contains steps, which is a group of tasks.
  • Tasks in steps are executed one-by-one, so you don't have to provide order explicitly.