Answers: <p>Ok, found it <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&amp;tabs=yaml#build-variables-devops-services" rel="nofollow noreferrer">here</a>:</p>
  <pre><code>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;username@live.com 
   - TFVC repo shelveset build: myshelveset;username@live.com
  
  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.
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-10-10T01:59:21.130Z
Answers: 2020-10-10T01:59:21.130Z
Answers: cheslijones
Answers: <p>If your after the branch name, and your branches don't include &quot;directories&quot; (example: releases/my_release), then <code>Build.SourceBranchName</code> will you give you &quot;The last path segment in the ref&quot;. So, if <code>Build.SourceBranch</code> is <code>refs/heads/master</code>, then Build.SourceBranch will be <code>master</code>.</p>
  <p>Your YAML:</p>
  <pre><code>trigger:
    branches:
      include:
      - master
      - staging
  ...
  manifests: |
    $(Pipeline.Workspace)/manifests/azure/${{ variables.Build.SourceBranchName }}/api.yaml
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-04-13T09:45:52.147Z
Answers: 2021-04-13T09:45:52.147Z
Answers: Walter Vos
Body: <p>Currently I have two separate Azure DevOps Pipeline config files:</p>
  <ul>
  <li><code>azure-pipelines-staging.yaml</code></li>
  <li><code>azure-pipelines-production.yaml</code></li>
  </ul>
  <p>Really the only differences in them are the:</p>
  <pre><code>trigger:
    branches:
      include:
      - master # or staging
  </code></pre>
  <p>And the directory where my k8s manifests are:</p>
  <pre><code>manifests: |
    $(Pipeline.Workspace)/manifests/azure/prod/api.yaml
  
  # or 
  
  manifests: |
    $(Pipeline.Workspace)/manifests/azure/staging/api.yaml
  </code></pre>
  <p>So ideally it would be something like:</p>
  <pre><code>trigger:
    branches:
      include:
      - master
      - staging
  ...
  manifests: |
    $(Pipeline.Workspace)/manifests/azure/$(branch)/api.yaml
  </code></pre>
  <p>Not quite seeing how to get <code>$(branch)</code> name in there. Suggestions?</p>
  
Tags: <azure-devops><azure><azure-pipelines><branch>
Title: One azure-pipeline.yaml for staging and production
UserDisplayName: cheslijones
ThreadText: # One azure-pipeline.yaml for staging and production
  
  (Asked by: username_0 on 2020-10-10)
  
  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?
  
  **Tags:** azure-devops, azure, azure-pipelines, branch
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2020-10-10. Score: 1 | Accepted answer
  
  Ok, found it [here](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#build-variables-devops-services):
  
  ```
  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;username@live.com 
   - TFVC repo shelveset build: myshelveset;username@live.com
  
  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.
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2021-04-13. Score: 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
  
  ```
  
  
  ---
  
  