0

~enter image description here

System variable System.PullRequest.TargetBranch cannot be used in templates. What is the workaround for below.

YAML file

using Environment dev this wrongly mapped instead of PROD

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Nikhil
  • 1
  • 1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Sep 21 '21 at 10:28

1 Answers1

0

It kind of depends where you want to use Environment variable. If in deployment job to set environment, you can't as it has to be known at compilation time.

If you want to use in place which can be established at runtime, you can use logging command to setup variable.


- pwsh: |
    if ( 'refs/heads/release-uat' -in @('$(Build.SourceBranch)','$(System.PullRequest.TargetBranch)') )
    {
        Write-Host "##vso[task.setvariable variable=Environment;]uat"
    }

However, variable set in that way can't be use in some places.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • using Environment dev this wrongly mapped instead of PROD. Please find the snapshot attachment in the question. – Nikhil Sep 27 '21 at 12:02