azure-devopsazure-pipelinescicdazure-pipelines-release-pipeline

Approval on azure release pipeline - on task level


I have the release pipeline and I would like to set the approval on the task level.

For example: I have the below powershell tasks and each of the task should have approve or disapprove to execute. if I dissaprove or approve SetupDatabricks task it still has to go to next task. The approval or dissaporval should not have the impact if next task should run or no (they should run).

enter image description here


Solution

  • In Azure DevOps, approvals are not set at the task level but can be configured at the stage level or between jobs with a manual intervention task.

    However, if you disapprove a stage or reject the manual intervention task, it will not go to next task as the pipeline is in a failed/rejected state.

    Workaround

    As you want the approval or disapproval should not have the impact if next task should run or no (they should run), you can try the following steps. With this workaround, we can control if the task is approved to run when you manually create a new release. The disadvantage is that you can't change the approvals state when the release is running.

    1. Create three variables in your release pipeline and enable the "Settable at release time" option. Create three variables
    2. Change your PowerShell tasks with the following sample script and use different variables for each task. sample PowerShell script
    $aproveSetupDatabricks = $env:aproveSetupDatabricks
    
    if ($aproveSetupDatabricks -eq "true") {
        Write-Host "approve SetupDatabricks"
        # Write your commands here.
    } else {
        Write-Host "disapprove SetupDatabricks"
    }
    
    1. Set the variables value when creating a release. Set the variables value when creating a release
    2. The Result: Only when the corresponding variable is set to true, the setup/deploy command in the PowerShell task will run and the approval or disapproval will not have the impact if next task will run or no (they should run). Result