简体   繁体   中英

Azure DevOps Releases skip tasks

I'm currently working on implementing CI/CD pipelines for my company in Azure DevOps 2020 (on premise). There is one requirement I just not seem to be able to solve conveniently: skipping certain tasks depending on user input in a release pipeline.

What I want: User creates new release manually and decides if a task group should be executed.

Agent Tasks:

 1. Powershell
 2. Task Group (conditional)
 3. Task Group
 4. Powershell

What I tried:

  • Splitting the tasks into multiple jobs with the task group depending on a manual intervention task.
    • does not work, if the manual intervention is rejected the whole execution stops with failed.
  • Splitting the tasks into multiple stages doing almost the same as above with the same outcome.
  • Splitting the tasks into multiple stages trigger every stage manually.
    • not very usable because you have to execute what you want in the correct order and after the previous stages succeeded.
  • Variable set at release creation (true/false).
    • Will use that if nothing better comes up but kinda prone to typos and not very usable for the colleagues who will use this. Unfortunately Azure DevOps seems to not support dropdown or checkbox variables for releases. (but works with parameters in builds)
  • Two Stages one with tasks 1,2,3,4 and one with tasks 1,3,4.
    • not very desireable for me because of duplication.

Any help would be highly appreciated!

Depends on what the criteria is for the pipelines to run. One recommendation would be two pipeline lines calling the same template. And each pipeline may have a true/false embedded in it to pass as a parameter to the template.

The template will have all the tasks defined in it; however, the conditional one will have a condition like:

 condition: and(succeeded(), eq('${{ parameters.runExtraStep}}', true)) 

This condition would be set at the task level.

Any specific triggers can be defined in the corresponding pipeline.

Here is the documentation on Azure YAML Templates to get you started.

Unfortunately, it's impossible to add custom condition for a Task Group, but this feature is on Roadmap. Check the following user voice and you can vote it:

https://developercommunity.visualstudio.com/idea/365689/task-group-custom-conditions-at-group-and-task-lev.html

The workaround is that you can clone the release definition (right click a release definition > Clone), then remove some tasks or task groups and save it, after that you can create release with corresponding release definition per to detailed scenario.

Finally I decided to stick with Releases and split my tasks into 3 agent jobs. Job 1 with the first powershell, job 2 with the conditional taskgroup that executes only if a variable is true and job 3 with the remaining tasks.

As both cece-dong and dreadedfrost stated, I could've achieved a selectable runtime parameter for the condition with yaml pipelines. Unfortunately one of the task groups needs a specific artifact from a yaml pipeline. Most of the time it would be the "latest", which can be easily achieved with a download artifacts task but sometimes a previous artifact get's chosen. I have found no easy way to achieve this in a way as convenient as it is in releases where you by default have a dropdown with a list of artifacts.

If found this blog post for anyone interested on how you can handle different build artifacts in yaml pipelines.

Thanks for helping me out!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM