gpt4 book ai didi

azure - 尽管值为 true,但阶段条件未评估为 true

转载 作者:行者123 更新时间:2023-12-02 08:23:14 25 4
gpt4 key购买 nike

我有一个运行阶段的条件。条件是true,但该阶段一直被跳过,我不知道为什么。

这是舞台:

stages:
- stage: UnitTests
displayName: Run unit tests on service...
condition: eq(stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'], true)
dependsOn: Changed
variables:
test: $[ stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'] ]
jobs:
- job: UnitTests
displayName: Running unit tests...
steps:
- bash: |
echo $(test)

或者将其分配给变量:

stages:
- stage: UnitTests
displayName: Run unit tests on service...
variables:
test: $[ stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'] ]
condition: eq(variables.test, true)
# dependsOn: Changed
jobs:
- job: UnitTests
displayName: Running unit tests...
steps:
- bash: |
echo $(test)

但是,如果我注释掉 conditiondependsOn,那么 echo $(test) 确实会打印出 true .

stages:
- stage: UnitTests
displayName: Run unit tests on service...
# condition: eq(stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'], true)
# dependsOn: Changed
variables:
test: $[ stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'] ]
jobs:
- job: UnitTests
displayName: Running unit tests...
steps:
- bash: |
echo $(test)

Starting: Bash
==============================================================================
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.182.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
Script contents:
echo true
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/119fb181-f890-4c1c-bffa-94142b0d51d9.sh
true
Finishing: Bash

这是检测更改的阶段:

stages:
- stage: Changed
displayName: Checks for changes in services and configs...
jobs:
- job: Changes
displayName: Checking for changes in services and configs...
steps:
- bash: |
mapfile -t servicesChanged < <(git diff HEAD origin/production --name-only | awk -F'/' 'NF!=1{print $1}' | sort -u)
echo "Total Changed: ${#servicesChanged[@]}"
if [[ ${#servicesChanged[@]} > 0 ]]; then
echo "Any services changed: True"
echo "##vso[task.setvariable variable=anyServicesChanged;isOutput=true]true"
fi
name: detectChange

所以我不确定我在这里做错了什么,当 conditiondependsOn 处于事件状态时,它会不断跳过此阶段。有什么建议吗?

最佳答案

当您在阶段上使用此条件(阶段取决于作业输出)时,您必须使用 dependencies 变量,而不是 stageDependencies。因此以下语法应该有效。

- stage: UnitTests
displayName: Run unit tests on service...
condition: eq(dependencies.Changed.outputs['Changes.detectChange.anyServicesChanged'], true)
dependsOn: Changed

参见:Stage depending on job output了解详情。

关于azure - 尽管值为 true,但阶段条件未评估为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66751545/

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