drs9222
drs9222

Reputation: 4508

Manually triggered stages in Azure Devops YAML Pipelines

I'd like to recreate a pipeline that looks something like this in YAML.

Release Pipeline

I have successfully recreated the first line (A) pipeline. A combination of dependsOn, environmentName, and environment approvals handles that. However, there doesn't seem to be a way to create the B and C pipelines in YAML.

I've seen several similar questions, but most were not quite what I was looking for or were very old had no solution. I suspect this isn't possible right now but wanted to ask to be sure.

Upvotes: 5

Views: 8225

Answers (4)

Alex
Alex

Reputation: 5247

you could either set-up a mandatory environment approval or add an additional stage with an ManualValidation@0 task like so:

- stage: approval
  displayName: 'Approval'
  dependsOn: ci
  jobs:
  - deployment: approval
    displayName: Approve
    timeoutInMinutes: 4320 # job times out in 3 days
    pool: server # note: the value 'server' is a reserved keyword which indicates this is an agentless job
    environment:
      name: ProdSA
      resourceType: VirtualMachine
    strategy: 
      runOnce:
        deploy:
          steps:
          - task: ManualValidation@0
            inputs:
              instructions: 'Approval required'
            timeoutInMinutes: 1440 # task times out in 1 day

result

enter image description here

enter image description here

note 1: the task will not work if you do not specify the pool: server, so I was not able to include the task inside of the actual dependent stage that executes on the remote agent. So in the setup like mine, you will need a separate stage for the approval.

note 2: you need the ManualValidation@0 specifically, not the ManualIntervention@8 task. I have been getting weird errors with the later

note 3: don't forget to set dependsOn: approval for the stages that follow next after approval stage.

Upvotes: 1

starian chen-MSFT
starian chen-MSFT

Reputation: 33728

You could control it per to the parameters, for example:

parameters:
- name: stageTest
  displayName: Run Stage test
  type: boolean
  default: false

trigger:
  - none

variables:      # pipeline-level
  system.debug: true

stages:
- stage: Build
  jobs:
  - job: Build
    steps:
    - script: echo "hello to my first Build"
- stage: Test
  dependsOn:
    - Build
  jobs:
  - job: Test
    steps:
    - script: echo "test"
- ${{ if eq(parameters.stageTest, true) }}: 
  - stage: B1
    dependsOn: []
    jobs:
    - job: B1
      steps:
      - script: echo "B1"
  - stage: B2
    dependsOn:
    - B1
    jobs:
    - job: B2
      steps:
      - script: echo "B2"

The parameter is stageTest and you could set the value (check or uncheck) when queue pipepeline.

enter image description here

On the other hand, you also could skip stage when run pipeline: Skipping stages in a YAML pipeline

Upvotes: 2

Hugh Lin
Hugh Lin

Reputation: 19461

I am afraid that it is currently impossible to implement the manually triggered stage like the UI of release pipeline in YAML pipeline.

At present, the function of specifying the stage to run is provided in yaml, but this only applies to manually triggered pipelines and cannot deploy the manual stage at any time as in the release pipleine.

According to your flow chart, you want your pipeline start with CI and keep the independence of manual stages will not affect the running of the pipeline. Splitting stages into multiple yaml pipelines should not be what you want, so you can follow the uservoice and vote for this ticket to look forward to the release of new features.

Upvotes: 0

Daniel Mann
Daniel Mann

Reputation: 59045

Put an approval in front of the first environment. It won't trigger until it's approved. That's as close as you're going to get right now.

Upvotes: 3

Related Questions