gpt4 book ai didi

azure - Azure Yaml 管道中的覆盖变量不起作用

转载 作者:行者123 更新时间:2023-12-02 06:37:25 24 4
gpt4 key购买 nike

我的目的是使用默认变量运行管道。变量createRelease 应该指示除了“TestApplication”之外还应该运行哪个作业。

伪代码:

RunJob('TestApplication')

if(!createRelease)
RunJob('BuildForDev')

if(createRelease)
RunJob('BuildForUatRelease')

不知何故,它不会覆盖 createRelease 的值。有人知道为什么不吗?

我的管道 yaml 如下所示:

trigger:
- main
- feature/*

pool:
vmImage: ubuntu-latest

variables:
- name: createRelease
value: false

stages:
- stage: CI_Build
displayName: Build and Test App
jobs:
- job: TestApplication
displayName: Building and testing
condition: always()
steps:
- task: Bash@3
displayName: Maven Test Application
inputs:
targetType: 'inline'
script: |
echo 'mvn test'
- job: BuildForDev
displayName: Build Application for Develop
dependsOn: TestApplication
condition: |
and(
succeeded('TestApplication'),
eq(variables['Build.SourceBranchName'], 'main'),
eq(variables.createRelease, 'false')
)
steps:
- task: Bash@3
displayName: Maven test Application
inputs:
targetType: 'inline'
script: |
echo mvn test
- job: BuildForUatRelease
displayName: Release Application
dependsOn: TestApplication
condition: |
and(
succeeded('TestApplication'),
eq(variables['Build.SourceBranchName'], 'main'),
eq(variables.createRelease, 'true')
)
steps:
- task: Bash@3
displayName: Set Git Credentials
inputs:
targetType: 'inline'
script: |
echo 'mvn release prepare'

Pipeline 中可以被覆盖的变量定义:

enter image description here

如何在运行前设置createRelease:

enter image description here

最佳答案

您在 YAML 中分配变量的值,该值将优先于队列时定义的变量。这样想可能会有所帮助:

  • 您使用 createRelease: True 变量对管道进行排队
  • Azure DevOps 为管道创建执行上下文并执行 pipeline.yml
  • 您的管道定义了 createRelease: False 的值

解决方法:

  1. 从 yaml 中删除 createRelease 变量

  2. 编辑管道:

  3. 点击变量:

  4. 添加新变量并设置 createRelease 变量的默认值。将其设置为允许用户在队列时更改值:

  5. 单击“确定”。

或者,您可能需要考虑创建参数而不是变量:

trigger:

parameters:
- name: createRelease
displayName: 'Create a Release'
type: boolean
default: false

stages:
- stage: ...
jobs:
- job: ...
steps:
- script: 'hello'
condition: ${{ eq( parameters.createRelease, 'true') }}

关于azure - Azure Yaml 管道中的覆盖变量不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71130484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com