I am trying to setup a Azure Devops build and release pipeline to build and deploy a Databricks job using Databricks assets bundle. I have been following the following Documentation: https://learn.microsoft.com/en-us/azure/databricks/dev-tools/ci-cd/ci-cd-azure-devops
The build pipeline is a simple one as given below which is triggered on merges to main and develop branch.
trigger:
branches:
include:
- feature/azure-pipeline
pool:
vmImage: ubuntu-22.04
steps:
- checkout: self
clean: true
fetchDepth: 1
persistCredentials: true
- bash: echo $(Build.SourceBranch)
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
inputs:
ArtifactName: 'DatabricksBuild'
Now, in the release I have an env variable which will depend on the branch which triggers the build. How would I save the triggering branch name in build pipeline to use it in the release part of the pipeline?
As far as I understand, your requirement is to retrieve the branch name within the release pipeline; the commits/merges into this branch trigger the upstream build pipeline, which then produces artifacts and triggers the downstream release pipeline.
For this, you may directly use the Predefined Variables of $(Build.SourceBranch)
and $(Build.SourceBranchName)
in your release pipeline; Azure Pipelines populates such variables for the designated primary artifact.
If you added multiple artifacts generated by different build pipelines, you may also use $(Release.Artifacts.{alias}.SourceBranch)
and $(Release.Artifacts.{alias}.SourceBranchName)
to get each triggering branch of different build pipeline artifacts.