【问题标题】:YAML pipeline : How to disable a template depending on variableYAML 管道:如何根据变量禁用模板
【发布时间】:2023-03-19 07:50:02
【问题描述】:

我有一个调用 AndroidSigning@3 步骤的 yaml 管道,它需要 apksignerKeystoreFile 输入。我想根据管道库中的变量禁用此步骤。 启动管道时出现此错误:

/build/pipelines/build-mobile-android.yml (Line: 42, Col: 14): Unexpected value 'ne(, 'release')'

感谢任何帮助

- group: variables-group

stages:
- stage: build
  jobs:
 - job: buil_app
   steps:
   - task: AndroidSigning@3
     enabled: ne(${{ variables.env }}, 'release')
     inputs:
       apkFiles: 'blabla'
       apksign: true

【问题讨论】:

    标签: azure-devops yaml azure-pipelines


    【解决方案1】:

    查看 YAML 架构参考,这似乎是不可能的

    steps:
    - script: string  # contents of the script to run
      displayName: string  # friendly name displayed in the UI
      name: string  # identifier for this step (A-Z, a-z, 0-9, and underscore)
      workingDirectory: string  # initial working directory for the step
      failOnStderr: boolean  # if the script writes to stderr, should that be treated as the step failing?
      condition: string
      continueOnError: boolean  # 'true' if future steps should run even if this step fails; defaults to 'false'
      enabled: boolean  # whether to run this step; defaults to 'true'
    

    enabled 必须是布尔值。您可以使用condition,然后使用ne( variables['env'], 'release'),它应该可以完成这项工作。

    【讨论】:

    • 似乎不起作用 /build/pipelines/build-mobile-android.yml (第 42 行,第 14 列):意外值 'ne(variables['env'], 'release ')'
    • 是的。我对此进行了测试,看来您需要在此处使用条件。
    • isn't ne(variables['env'], 'release') 返回一个布尔值到 'enabled' ?
    【解决方案2】:
    steps:
    - task: AndroidSigning@3
      condition: eq(variables['env'], 'release') 
      displayName: AndroidSigning - enabled
      enabled: true
      inputs:
        apkFiles: 'blabla'
        apksign: true
    - task: AndroidSigning@3
      condition: ne(variables['env'], 'release') 
      displayName: AndroidSigning - disable
      enabled: false
      inputs:
        apkFiles: 'blabla'
        apksign: true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 2020-01-31
      • 2021-05-12
      • 1970-01-01
      • 2019-10-04
      • 2020-06-12
      • 2022-07-21
      相关资源
      最近更新 更多