Wednesday 28 October 2020

Implementing a CD YAML Pipeline with Deployment Job

We have discussed couple of things related to implementing CD with YAML in the posts “Trigger Deployment YAML Pipeline Once YAML Build Completed” and in “Prevent Checking Out the Repo in CD YAML Pipeline”. However, the checkout of the repo only happens if use the normal job syntax for deployment job as well. Ideally, we should be using job of type of “deployment” in our CD YAML pipelines so the checkout of repo would not happen by default as well as it will be required to define an environment for deployment. The environment helps us to keep track of our deployments. When we implement the CD YAML with deployment jobs download of artifacts would be automatic. Let’s find out how the deployment job implementation looks like.

A deployment job

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

Deployment job demands for env and if the env does not exist it will create it in your team project. If you create the environment manually and specify the same name in the pipeline the environment will be used for the job. We can keep track of deployments related to an environment and add approvals and checks for an environment which we will discuss in later post. Deployment job demands for a strategy and “runOnce” is only supported for none Kubernetes and no one VM based type of deployments. For VM based deployments you can setup “runOnce” or “rolling” deployments. Canary deployment is only supported in Kubernetes deployments.

We can try a deployment job as in below full pipeline and we can see the execution information from the environment.

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"



Notice that the deployment job automatically download artifacts from the resource build pipeline similar to classic pipelines and checkout of repo has not happened by default.



No comments:

Popular Posts