Friday, 9 October 2020

Prevent Checking Out the Repo in CD YAML Pipeline

In the previous post “Trigger Deployment YAML Pipeline Once YAML Build Completed” (https://chamindac.blogspot.com/2020/10/trigger-deployment-yaml-pipeline-from.html) we have discussed how to separate the deployment pipeline from the build pipeline, in Azure DevOps YAML pipeline implementations and to trigger a CD pipeline from the CI build once completed. However, if you check carefully that post implementation of CD it is still checking out the code repository, even though it is not necessary to checkout code being the deployment pipeline. Let’s see how we can avoid checking out repo in the CD YAML.

 UPDATE: This is when you use the normal jobs in deployment YAML as well. If you are using deployment as job with environment in YAML pipelines for CD this problem would not occur and your artifact download from build will be automatic. See post "Implementing a CD YAML Pipeline with Deployment Job"

resources:
  pipelines:
  - pipelineApp_CI  
    project:  YAML_CICD 
    sourceApp.CI  
    triggertrue

stages:
stageDev
  displayNameDeploy to Dev
  jobs:
  - deploymentDeployDev
    pool:
      vmImage'windows-latest'
    environmentmyapp-dev
    strategy:
       runOnce:
        deploy:
          steps:
          - pwsh: |
              Write-Host "Deploy to Dev"
              Write-Host "We do nothing here"


Below discussion only valid if you use job to define your deployment steps, instead of above.

Problem

CD YAML below checks out the repo.

resources:

  pipelines:
  - pipelineApp_CI  
    project:  YAML_CICD 
    sourceApp.CI  
    triggertrue

stages:
stageDev
  displayNameDeploy to Dev
  jobs:
  - jobDeployDev
    pool:
      vmImage'windows-latest'
    steps:
    - pwsh: |
        Write-Host "Deploy to Dev"
        Write-Host "We do nothing here"


Solution

You can add the below step to prevent check out of the repo in the CD YAML.

    steps:
    - checkoutnone

The full pipeline would be as below.

resources:
  pipelines:
  - pipelineApp_CI  
    project:  YAML_CICD 
    sourceApp.CI  
    triggertrue

stages:
stageDev
  displayNameDeploy to Dev
  jobs:
  - jobDeployDev
    pool:
      vmImage'windows-latest'
    steps:
    - checkoutnone

    - pwsh: |
        Write-Host "Deploy to Dev"
        Write-Host "We do nothing here"

Execution of this CD pipeline does not check out repo as you can see blow.



No comments:

Popular Posts