简体   繁体   English

Azure 管道 yml - 更改任务中的值并根据 if else 条件执行

[英]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.

相关问题 如何配置基于条件的管道 | Azure管道 - How to configure condition based pipeline | Azure Pipeline 您可以从 azure 管道构建 yml 中执行另一个构建 yml 吗? - Can you execute another build yml from inside a azure pipeline build yml? Azure - 基于 YAML 的管道中的自定义条件 - Azure - custom condition in YAML based pipeline Azure 管道启用基于变量值的任务 - Azure Pipeline Enable Task base on variable value 当条件符合 azure devops 管道的 ansible 任务中的主机名时 - when condition as per hostname in ansible task of azure devops pipeline 如何在 Azure 管道任务 AzureResourceGroupDeployment 中为 overrideParameters 添加条件 - How do I add a condition to overrideParameters in Azure pipeline task AzureResourceGroupDeployment Azure Devops 中使用任务“调用 Rest API”的管道失败错误:“&lt;&gt;.yml(行:1,列:1):序列不是预期的” - Pipeline in Azure Devops using Task "Invoke Rest API" is failing Error:"<>.yml (Line: 1, Col: 1): A sequence was not expected" 基于输出结果的 Azure Pipeline 任务(通过或失败) - Azure Pipeline Task (Pass or Fail) based on the output results 如何解决 Azure devops 管道 yml 中的“意外值‘阶段’天蓝色管道” - How to resolve "unexpected value 'stages' azure pipelines" in Azure devops pipeline yml 更改 Azure Pipeline 的变量组值 - Change variable group value of Azure Pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM