Friday 30 October 2020

Obtaining Build Number, Build Id etc. of Another CI Build Pipeline in the CD/Release YAML Pipeline

Let’s look at how we can specify the artifact version to download based on the resource CI build linked to the CD pipeline and check on how to obtain the resource CI build pipeline information such as build number, build id definition id etc., in the CD YAML pipeline.

You can use another build pipeline as a source in your YAML CD pipeline and trigger a deployment in the CD pipeline based on the build pipeline completion. See related posts.

Whether CD pipeline is triggered manually or by the source build pipeline, you can retrieve useful information such as build number, build id of the source pipeline using the below syntax.










Provided that you have referred another pipeline as resource for the CD pipeline with below shown syntax.

  - pipelineApp_CI  
    project:  YAML_CICD 

Example CD YAML pipeline implementation is below.

  - pipelineApp_CI  
    project:  YAML_CICD 

  displayNameDeploy to Dev
  - deploymentDeployDev
          - pwsh: |
              Write-Host ('CI build denition id: ' + '$(resources.pipeline.App_CI.pipelineID)') 
              Write-Host ('CI build number: ' + '$(resources.pipeline.App_CI.runName)')
              Write-Host ('CI build id: ' +'$(resources.pipeline.App_CI.runID)')
              Write-Host ('CI build run url: ' +'$(resources.pipeline.App_CI.runURI)')
              Write-Host ('CI build branch: ' +'$(resources.pipeline.App_CI.sourceBranch)')
              Write-Host ('CI build commit: ' +'$(resources.pipeline.App_CI.sourceCommit)')
              Write-Host ('CI build source provider: ' +'$(resources.pipeline.App_CI.sourceProvider)')
              Write-Host ('CI build requested by user name: ' +'$(resources.pipeline.App_CI.requestedFor)')
              Write-Host ('CI build requested by user id: ' +'$(resources.pipeline.App_CI.requestedForID)')

Once the pipeline is executed you can see the information of the source build pipeline printed in your CD/release YAML pipeline.

These values would be useful to retrieve packages in the CD/release pipeline, which are published by build pipeline as artifacts, in the build itself or as NuGet packages to the artifact feeds, using the CI build’s, build number as the package version. We can see usage of the values obtained from source CI build in the CD/release pipeline in a next post.

Related Posts

· We have discussed how to specify a CI pipeline as a resource and a trigger for the CD YAML pipeline in the post “Trigger Deployment YAML Pipeline Once YAML Build Completed”.

· The way to select a particular build while triggering YAML CD pipeline was described in the post “Selecting Particular Source CI YAM Pipeline Build While Manually Triggering a YAML CD Pipeline”.

· The correct way of setting up CD YAMlL with deployment job is explained in the post "Implementing a CD YAML Pipeline with Deployment Job".

No comments:

Popular Posts