0

I'm porting one of our release pipelines from ADO classic to YAML.

Neither classic nor YAML allow you to select jobs/tasks while creating the run.

At least in classic, once the release is created, you can disable a stage's jobs/tasks for that specific release before triggering the stage.

In YAML, however, only stages are selectable on the run creation screen. But after the run is started, I can't find a way to disable tasks and/or jobs like I can in classic.

Oddly enough, after a YAML stage runs there's an option to "Rerun failed jobs."

So my question is, is it possible to enable/disable jobs and/or tasks when creating a new YAML pipeline run (or after creating, but before triggering a stage)?

Matt
  • 3,658
  • 3
  • 14
  • 27
dbconfession
  • 1,147
  • 2
  • 23
  • 36

1 Answers1

1

After creating the pipeline, I am afraid that there is no existing option can cancel a singal stage before triggering.

For a workaround, you can create Pipeline environment and add the Approval check. Then you can use the Environment in your stage.

In this case, before running this stage, you can stop the running of this stage by denying approval.

enable/disable jobs and/or tasks when creating a new YAML pipeline run

To achieve this requirement, you can use the If Expression and Runtime Parameters in Yaml Pipeline.

Here is an example:

parameters:
  - name: test1
    type: string
    default: false
    values:
      - true
      - false

pool:
  vmImage: ubuntu-latest

stages:
 
  - stage: testA
    jobs:
    - ${{ if eq(parameters['test1'], 'true' ) }}:
      - job: test1
        steps:
           - script: echo 1
    - job: test2
      steps:
        - script: echo 1
     
  - stage: testB
    jobs:
      - job: test3
        steps:
          - script: echo 1
    

When you run the Pipeline, you can select the value to run the jobs/task.

enter image description here

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • thanks! yeah I'm already leveraging the env approval as a work-around. Unfortunately, this triggers an alert email for each env that requires an approval. And since there isn't a way to manually trigger a stage, I'm already using approvals as a work-around for several stages already. Yes, these alerts can be filtered in outlook, but that's going to annoy people and isn't a solid solution. I did find a feature request to allow manual triggers for stages/jobs. It had enough upvotes where the moderator said they're adding this feature to the queue. Hopefully that comes soon. – dbconfession Oct 15 '21 at 23:46
  • @Kevin Lu-MSFT Hi Kevin, this definitely works. The list of stages in "Stages to Run" section changes based on the checkmark in the pipeline parameter. The same with pipeline, it doesn't show the other stages. I think that it is the If expression that does that. Would it be possible to still have this logic of parameter toggling but still show the skipped stages in the pipeline run? Maybe by using the condition property instead of this If construct? – Oliver Nilsen Jul 19 '23 at 11:52
  • @Kevin LU-MSFT I just tried used condition property instead: condition: and(succeeded(), eq('${{ parameters.CleanUpEnvironments }}', false)) which will show the skipped stages in the pipeline run view. I guess it is a preference taste. The If construct you are using here is a compile-time expression, so based on the toggle of the parameter it will only show those stages in the "Stages to Run" view before even running the pipeline. I think I prefer this option at least when I am tearing down environments, so I can clearly distinguish between a normal deployment and a tear down environment. – Oliver Nilsen Jul 19 '23 at 12:16