Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

Azure pipelines YAML release, parallel deployments

I am working on pipelines for several dotnet core projects, that all runs on a Windows Self-Hosted agent behind a firewall.

The build pipelines are ok, I wrote few pipelines in Yaml to act as release pipelines. Each time, the first stage builds the project, the next stage release to staging and we use the environments to enforce the approval before release to preprod and approval again, before prod.

I have several projects where the solution has those projects:

  • Core
  • UI
  • API

I created release pipelines for each of them that all use the same template: parameters:

stages:
  - stage: Init_1
    jobs:
      [***]

  - stage: Build_1
    dependsOn: Init_1
    jobs:
      - job: Init
      - job: Package
      - job: Build

  - stage: Deploy2ST_1
    dependsOn: Build_1
    jobs:
    - deployment: MoveTo_Staging
      environment: 'myApp ST'
      strategy:
           runOnce:
             deploy:
               steps:
                - task: DownloadPackage@1
                - task: PowerShell@2
                - task: PowerShell@2

  [***]
  and so on for preprod and prod

The release pipeline calls the template like this :

trigger:
  - none

pool:
  name: '***'

stages:
  - stage: InitRelease
    jobs:
    - job: 'InitJob'
      steps: [***]

  - template: myTemplate.yml@templates
    parameters:
      [* parameters for one project *]

This works but I was asked to create one pipeline that releases all three projects. I tried to call the templates several times:

stages:
  - stage: InitRelease
    jobs:
    - job: 'InitJob'
      steps: [***]

  - template: myTemplate.yml@templates
    parameters:
      [* parameters for project 1*]

  - template: myTemplate.yml@templates
    parameters:
      [* parameters for project 2*]

  - template: myTemplate.yml@templates
    parameters:
      [* parameters for project 3*]

The issue I have is that stages are run sequentially, it will stop running when the first one requests an approval to go to preprod

I tried to have the templates as jobs to run in parallel in one big stage: stages:

- stage: OneStageToRunThemAll
  jobs:
  - template: myTemplate.yml@templates
    parameters:
      [* parameters for project 1*]

  - template: myTemplate.yml@templates
    parameters:
      [* parameters for project 2*]

  - template: myTemplate.yml@templates
    parameters:
      [* parameters for project 3*]

but I get this error : Unexpected value 'stages', I'm guessing that stages can be inserted inside jobs.

The output I would like to get is like this:

 |
 |- Init Project 1 - Init_1 - Build_1 - Deploy2ST_1 - Waiting for approval
 |
 |- Init Project 2 - Init_1 - Build_1 - Deploy2ST_1 - Waiting for approval
 |
 |- Init Project 3 - Init_1 - Build_1 - Deploy2ST_1 - Waiting for approval

Can that be done ?

Thanks

question from:https://stackoverflow.com/questions/66065435/azure-pipelines-yaml-release-parallel-deployments

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Azure pipelines YAML release, parallel deployments

That because the pipeline will be executed in order by default, if we do not specify the keyword dependsOn.

To resolve this issue, we could try to add the keyword dependsOn in the template at the first stage:

stages:
  - stage: Init_1
    dependsOn: InitRelease
    jobs:
      [***]

As the test result, stage Angular and build run in parallel:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...