i'm trying to set the BuildConfiguration based on the triggered branch using powershell
anyone know how this could be done?
switch($env:Build.SourceBranchName) {
'master' {$env:BuildConfiguration = Release; break;}
'staging' {$env:BuildConfiguration = Staging; break;}
'develop' {$env:BuildConfiguration = Dev; break;}
}
you can set variables at the top of your yaml pipeline and use them at will.
variables:
${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
deployTarget: prod
${{ if eq(variables['Build.SourceBranchName'], 'develop') }}:
deployTarget: dev
and to use:
- task: CmdLine@2
displayName: Display deployment
inputs:
script: |
echo '${{ variables.deployTarget }}'
finally got this working with
switch(${env:BUILD_SOURCEBRANCH}) {
'refs/heads/master' {Write-Host "##vso[task.setvariable variable=BuildConfiguration]Release"; }
'refs/heads/staging' {Write-Host "##vso[task.setvariable variable=BuildConfiguration]Staging"; }
'refs/heads/develop' {Write-Host "##vso[task.setvariable variable=BuildConfiguration]Dev"; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With