azureazure-devopsazure-pipelinesazure-aksazure-pipelines-build-task

Is Azure Pipeline Interactive? Can User Input be Used during runtime of Pipeline Stages?


I'm wondering if Azure Pipelines support interactive user input during execution. Specifically, can user input be utilized in next stage of the pipeline? Any insights or examples would be appreciated.

I've tried ManualIntervention & ManualValidation tasks in Azure pipeline, which should actually prompt user for inputs, but it's not. These are the possible ways listed official Microsoft page. Ref:https://learn.microsoft.com/en-us/azure/devops/pipelines/release/approvals/?view=azure-devops&tabs=yaml


Solution

  • As others are suggesting, there is no built in way to parse variables in during a pipeline run, only variables created in yaml/code can be parsed to subsequent steps/jobs/stages.


    To achieve something like you are describing, you can add approver gates on the stages that force a user with the correct privileges to click an approve button before the stage commences. There are several ways to include approvers on your pipeline runs. See here.

    Before an approver clicks the approve button, then can modify variables stored in a third party vault, such as an Azure Key Vault. Once the stage begins, it will grab the updated variables.

    To achieve this, you will need multiple stages in your yaml. You can get the pipeline to automatically wait for an approver at any stage by including a deployment job that has an approver gate on it. To configure this:

    1. Navigate to Pipelines -> Environments in Azure DevOps
    2. Create a New Environment. For resources, select None.
    3. Go to the Approvals and checks tab, and add a mandatory reviewer

    enter image description here

    This will force your pipeline to wait for approval in the middle of a run:

    enter image description here

    At this point, if any variables need to be edited, the approver can manually go into an Azure Key Vault and modify any variable values. This can easily be done by anyone with the correct RBAC roles by clicking on the variables.

    enter image description here

    You can then include pipeline steps to retrieve, then save those KeyVault variables as pipeline variable.

    stages:
    - stage: Stage1
      jobs:
      - job: Job1
        steps:
        - task: PowerShell@2
          displayName: Print all variables
          inputs:
            targetType: "inline"
            script: |
              Write-Host "Example script"
    
    - stage: Stage2
      dependsOn: Stage1
      jobs:
      - deployment: Job2
        environment: ApprovalTest
        strategy:
          runOnce:
            deploy:
              steps:
              - task: AzureKeyVault@2
                displayName: Get KeyVault secrets
                inputs:
                  azureSubscription: $(serviceConnection)
                  KeyVaultName: MyAzureKeyVault
                  SecretsFilter: "*"
    
              - task: PowerShell@2
                displayName: Save KeyVault secrets
                inputs:
                  targetType: "inline"
                  script: |
                    Write-Host "##vso[task.setvariable variable=var1]$(var1)"
                    Write-Host "##vso[task.setvariable variable=var2]$(var2)"
                    Write-Host "##vso[task.setvariable variable=var3]$(var3)"