skip to Main Content

I have successfully created a CI/CD pipeline for Azure Data Factory with Azure DevOps using yaml templates, see below. This in contrast to creating the same pipelines using Azure DevOps ‘Classic Editor’

When creating Build/Release pipelines using Classic Editor I have the option to create Pre-Deployment options such as shown in the image – in particular I would like to setup ‘Pre-deployment approvals.

enter image description here

Is there a similar option to choose Pre-deployment approvals from any of the following yaml templates:
enter image description here

My yaml code is as follows:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- adf_publish

pool:
  vmImage: ubuntu-latest

steps:
- script: |
    tree $(System.DefaultWorkingDirectory)
  displayName: Show file structure of System.DefaultWorkingDirectory during a build


- task: AzurePowerShell@5
  inputs:
    displayName: PreDeployment
    azureSubscription: 'NewConnectionName'
    ScriptType: 'FilePath'
    ScriptPath: '$(System.DefaultWorkingDirectory)/caplogic-warehouse-dev-df/PrePostDeploymentScript.ps1'
    ScriptArguments: '-armTemplate "$(System.DefaultWorkingDirectory)/caplogic-warehouse-dev-df/ARMTemplateForFactory.json" -ResourceGroupName $(ResourceGroup) -DataFactoryName $(DataFactory) -predeployment $true -deleteDeployment $false'
    azurePowerShellVersion: 'LatestVersion'

- task: AzureResourceManagerTemplateDeployment@3
  inputs:
    deploymentScope: 'Resource Group'
    azureResourceManagerConnection: 'NewConnectionName'
    subscriptionId: '5fa2700d-738a-444e-a643-28241a29d08d'
    action: 'Create Or Update Resource Group'
    resourceGroupName: '$(ResourceGroup)'
    location: '$(Location)'
    templateLocation: 'Linked artifact'
    csmFile: '$(System.DefaultWorkingDirectory)/caplogic-warehouse-dev-df/ARMTemplateForFactory.json'
    csmParametersFile: '$(System.DefaultWorkingDirectory)/caplogic-warehouse-dev-df/ARMTemplateParametersForFactory.json'
    overrideParameters: '-factoryName $(DataFactory)'
    deploymentMode: 'Incremental'


- task: AzurePowerShell@5
  inputs:
    azureSubscription: 'NewConnectionName'
    ScriptType: 'FilePath'
    ScriptPath: '$(System.DefaultWorkingDirectory)/caplogic-warehouse-dev-df/PrePostDeploymentScript.ps1'
    ScriptArguments: '-armTemplate "$(System.DefaultWorkingDirectory)/caplogic-warehouse-dev-df/ARMTemplateForFactory.json" -ResourceGroupName $(ResourceGroup)  -DataFactoryName $(DataFactory) -predeployment $false -deleteDeployment $true'
    azurePowerShellVersion: 'LatestVersion'

I was thinking that one of the following task could be used to pause a the pipeline until some intervention was approved
enter image description here

But I couldn’t get either of the above to tasks to work inside my yaml

I get the error

Job Job: Step references task 'ManualIntervention' at version '8.238.0' which is not valid for the given job target.

I have tried the following yaml code I found online

jobs:
- job: waitForValidation
  displayName: Wait for external validation  
  pool: server    
  timeoutInMinutes: 4320 # job times out in 3 days
  steps:   
   - task: ManualValidation@0
     timeoutInMinutes: 1440 # task times out in 1 day
     inputs:
         notifyUsers: |
            [email protected]
         instructions: 'Please validate the build configuration and resume'
         onTimeout: 'resume'

But I get the following error:

/caplogic-warehouse-dev-df/azure-pipelines-5.yml (Line: 77, Col: 1): Unexpected value 'jobs'

I have updated the yaml code to reflect the code that @Vlad kindly helped me with:

trigger:
- adf_publish

pool:
  vmImage: ubuntu-latest

steps:
- script: |
    tree $(System.DefaultWorkingDirectory)
  displayName: Show file structure of System.DefaultWorkingDirectory during a build

- task: ManualValidation@0
  timeoutInMinutes: 1440 # task times out in 1 day
  inputs:
      notifyUsers: |
          [email protected]
      instructions: 'Please validate the build configuration and resume'
      onTimeout: 'resume'

However, I’m still getting the error:

Job Job: Step references task 'ManualValidation' at version '0.238.0' which is not valid for the given job target.

There is probably something very obvious that I’m missing, but I can’t see it.

2

Answers


  1. Error says: Unexpected value 'jobs'.

    For ManualValidation you have used a snippet with structure:

    jobs:
      - job:
        steps:
          - task
    

    But in your original pipeline you only have structure:

    steps:
      - task
    

    If in the beginning of the pipeline definition you use steps without stages and jobs, it means that you are implicitly skipping the jobs level and define only one single job.


    You should check out key concepts of Azure Pipelines to understand it better.

    Key concepts

    Key Concepts of Azure Pipelines

    Image from https://learn.microsoft.com/en-us/azure/devops/pipelines/get-started/key-pipelines-concepts?view=azure-devops

    Concepts:

    • A trigger tells a pipeline to run.
    • A pipeline is made up of one or more stages. A pipeline can deploy to one or more environments.
    • A stage is a way of organizing jobs in a pipeline and each stage can have one or more jobs.
    • Each job runs on one agent. A job can also be agentless.
    • Each agent runs a job that contains one or more steps.
    • A step can be a task or script and is the smallest building block of a pipeline.
    • A task is a prepackaged script that performs an action, such as invoking a REST API or publishing a build artifact.

    Something like this should work:

    trigger:
    - adf_publish
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
    - script: |
        tree $(System.DefaultWorkingDirectory)
      displayName: Show file structure of System.DefaultWorkingDirectory during a build
    
    # Steps before manual approval
    # ...
    
    - task: ManualValidation@0
         timeoutInMinutes: 1440 # task times out in 1 day
         inputs:
             notifyUsers: |
                [email protected]
             instructions: 'Please validate the build configuration and resume'
             onTimeout: 'resume'
    
    # Steps after manual approval
    # ...
    
    
    Login or Signup to reply.
  2. In YAML pipelines, you can configure manually approvals like as below:

    1. If the stage contains deploy jobs that need to target to environments, You can directly set approvals on the environments. If you have set multiple approval checks on the environment, you can change execution order of the checks to let then evaluate as Pre-check approval or Post-check approval.

      enter image description here

    2. If the stage does not contain any deploy jobs, you can configure a Server job (Agentless job) to run the ManualValidation@0 task.

      • Add the a Server job as the first job in the stage and let other jobs depend on it.
      • Add a ManualValidation@0 task in the Server job to pause a the YAML pipeline run to wait for manual approval.
    stages:
    - stage: A
      jobs:
      - job: approvalsA
        displayName: 'Manual Approvals'
        pool: server
        steps:
        - task: ManualValidation@0
          timeoutInMinutes: 1440  # Set time out.
          inputs:
          # You can add multiple approvers.
            notifyUsers: |
              [email protected]
              [email protected]
            instructions: 'Please validate and approve the run on this stage.'
    
      - job: A1
        dependsOn: approvalsA
        steps:
        . . .
    
      - job: A2
        dependsOn: approvalsA
        steps:
        . . .
    
    - stage: B
      jobs:
      - job: approvalsB
        displayName: 'Manual Approvals'
        pool: server
        steps:
        - task: ManualValidation@0
          timeoutInMinutes: 1440
          inputs:
            notifyUsers: |
              [email protected]
              [email protected]
            instructions: 'Please validate and approve the run on this stage.'
    
      - job: B1
        dependsOn: approvalsB
        steps:
        . . .
    
      - job: B2
        dependsOn: approvalsB
        steps:
        . . .
    

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search