[英]Azure pipeline yml - Change value in task and execute based on if else condition
In the below task, based on the branch, how do I specify a different value for assembleQaDebug .在以下任务中,基于分支,我如何为assembleQaDebug指定不同的值。 If the branch is qa it has to be assembleQaDebug ;
如果分支是 qa 它必须是assembleQaDebug ; if develop, it has to be assembleDevelopDebug .
如果开发,它必须是assembleDevelopDebug 。 And if prod branch, it has to be assembleProdRelease .
如果 prod 分支,它必须是assembleProdRelease 。 What is the best approach doing this, if there is one.
这样做的最佳方法是什么,如果有的话。 Any help is much appreciated.
任何帮助深表感谢。
- task: Gradle@3
displayName: 'Build Task'
continueOnError: false
inputs:
tasks: assembleQaDebug -PversionCode=$(Build.BuildId) -PdisablePreDex --no-daemon
publishJUnitResults: false
The values has to be specified in 'variables' section:这些值必须在“变量”部分中指定:
variables:
- name: tf_version
value: latest
- name: variablegroupname
${{ if eq(variables['Build.SourceBranchName'], 'develop') }}:
value: assembleDevelopDebug
${{ if eq(variables['Build.SourceBranchName'], 'qa') }}:
value: assembleQaDebug
- name: env
${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
value: prod
${{ if eq(variables['Build.SourceBranchName'], 'dev') }}:
value: develop
Like this you can add your variables and depending on your stage you can replace the values.像这样,您可以添加变量,并根据您的阶段替换这些值。
Not sure if it's the best way to do this, but I love using variables for those kind of use cases, so check this one:不确定这是否是最好的方法,但我喜欢在这些用例中使用变量,所以检查一下:
...
variables:
- name: assembleDebug
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/prod') }}:
value: assembleProdRelease
${{ elseif eq(variables['Build.SourceBranch'], 'refs/heads/qa') }}:
value: assembleQaDebug
${{ elseif eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}:
value: assembleDevelopDebug
...
- task: Gradle@3
displayName: 'Build Task'
continueOnError: false
inputs:
tasks: $(assembleDebug) -PversionCode=$(Build.BuildId) -PdisablePreDex --no-daemon
publishJUnitResults: false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.