I have requirement to trigger pipeline when pull request is raised in ADO and when the triggered pipeline gets success, merge will be processed (using Branch policies). default value for environment parameter is NONPROD, but when pipeline auto triggers, I want to choose other environment based on target branch like NFT for develop and PROD for main.
I have tried with below code to set the variable and tried conditional parameter with predefined variable [‘System.PullRequest.targetBranchName’], but looks like i am able to see expected target branch in output but condition is not executing.
variables:
- name: mode
value: 'apply'
- name: environment
${{ if eq( variables['System.PullRequest.targetBranchName'], 'main' ) }} :
value: 'PROD'
${{ if eq( variables['System.PullRequest.targetBranchName'], 'develop' ) }} :
value: 'NFT'
${{ else }}:
value: 'NONPROD'
Below is the stage where i am trying to check the values.
stages:
- stage: setprerequisites
displayName: "setprerequisites"
jobs:
- job: checkvariables
displayName: "check variables"
steps:
- script: |
echo "source working directory --> $(System.DefaultWorkingDirectory)"
echo "selected default environmentparameter --> ${{ parameters.environment }}"
echo "selected environment from variables --> $(environment)"
echo "target branch --> $(System.PullRequest.targetBranchName)"
echo "selected terraform mode to apply --> ${{ parameters.mode }}"
echo "terraform ${{ parameters.mode }} will be applied on $(environment) environment"
Below is the Output :
- selected environment from variables –> NONPROD
- target branch –> develop
- selected terraform mode to apply –> apply
Thanks in advance