我正在使用azure管道。这是我需要的:
当某件事被推向高手时,我希望它运行构建过程并将工件移至/ production。
当将某些内容推送到暂存时,我希望它运行构建过程并将工件移至/ staging。
我有一个Yaml文件。我不想有不同的管道。
所以,假设我在Yaml中有类似的内容。
触发:
master
staging
现在,这可行,但是我还需要根据master分支或staging分支设置env变量,因为这些分支告诉哪个分支用于生产,哪个分支用于生产。
除非我使用脚本节并切换类似以下的语句,否则我将找不到任何方法:
steps:
- task: PowerShell@2
displayName: Determine source branch
inputs:
targetType: 'inline'
script: |
switch(${env:BUILD_SOURCEBRANCH}) {
'refs/heads/master' {Write-Host "##vso[task.setvariable variable=admiralBaseUri]https://admiral-p.azurefd.net"; }
'refs/heads/development' {Write-Host "##vso[task.setvariable variable=admiralBaseUri]https://admiral-d.azurefd.net"; }
default {Write-Host "##vso[task.setvariable variable=admiralBaseUri]NONE"; }
}
问题:有什么方法比这种方法更好吗?您如何处理这种情况?