0

Currently I have two separate Azure DevOps Pipeline config files:

  • azure-pipelines-staging.yaml
  • azure-pipelines-production.yaml

Really the only differences in them are the:

trigger:
  branches:
    include:
    - master # or staging

And the directory where my k8s manifests are:

manifests: |
  $(Pipeline.Workspace)/manifests/azure/prod/api.yaml

# or 

manifests: |
  $(Pipeline.Workspace)/manifests/azure/staging/api.yaml

So ideally it would be something like:

trigger:
  branches:
    include:
    - master
    - staging
...
manifests: |
  $(Pipeline.Workspace)/manifests/azure/$(branch)/api.yaml

Not quite seeing how to get $(branch) name in there. Suggestions?

2 Answers 2

1

Ok, found it here:

Build.SourceBranch  

The branch of the triggering repo the build was queued for. Some examples:

 - Git repo branch: refs/heads/master 
 - Git repo pull request: refs/pull/1/merge 
 - TFVC repo branch: $/teamproject/main 
 - TFVC repo gated check-in: Gated_2016-06-06_05.20.51.4369;[email protected] 
 - TFVC repo shelveset build: myshelveset;[email protected]

When your pipeline is triggered by a tag: refs/tags/your-tag-name
When you use this variable in your build number format, the forward slash characters (/) are replaced with underscore characters _).

Note: In TFVC, if you are running a gated check-in build or manually building a shelveset, you cannot use this variable in your build number format.
0

If your after the branch name, and your branches don't include "directories" (example: releases/my_release), then Build.SourceBranchName will you give you "The last path segment in the ref". So, if Build.SourceBranch is refs/heads/master, then Build.SourceBranch will be master.

Your YAML:

trigger:
  branches:
    include:
    - master
    - staging
...
manifests: |
  $(Pipeline.Workspace)/manifests/azure/${{ variables.Build.SourceBranchName }}/api.yaml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.