gpt4 book ai didi

azure - 作业条件在前一阶段使用后评估为 "null"

转载 作者:行者123 更新时间:2023-12-03 01:25:00 25 4
gpt4 key购买 nike

我的 PR 管道的结构如下所示:

trigger: none

resources:
- repo: self

variables:
- template: templates/variables.yaml

pool:
vmIMage: $(vmImageName)

stages:
- template: templates/changed.yaml
parameters:
comparedTo: origin/production
- template: templates/unitTests.yaml
- template: templates/build.yaml
parameters:
services:
- api
- admin
- admin-v2
- client
tag: test
tagVersion: latest
- template: templates/integrationTests.yaml
- template: templates/seleniumTests.yaml

change.yaml 基本上确定了哪些微服务已更改,以便在没有更改的情况下避免构建、测试和部署服务。

parameters:
- name: comparedTo
default: ''

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 ${{ parameters.comparedTo }} --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: detectChanges

如果 anyServicesChanged = true,后续阶段中的作业条件将确定作业是否应运行。

我目前正在测试的内容,始终是true

它到达 unitTests.yaml 并正常运行(通过):

stages:
- stage: UnitTests
displayName: Run unit tests on service...
condition: succeeded()
dependsOn: Changed
jobs:
- job: UnitTests
condition: or(eq(stageDependencies.Changed.Changes.outputs['detectChanges.anyServicesChanged'], true), eq(variables['Build.Reason'], 'Manual'))
displayName: Running unit tests...
steps:
- bash: |
echo "Running unit tests..."

然后它到达 build.yaml 并跳过它:

parameters:
- name: services
type: object
default: []
- name: tag
default: ''
- name: tagVersion
default: ''

stages:
- stage: BuildAndPush
displayName: Build and Push Docker images of services...
condition: succeeded()
dependsOn: UnitTests
jobs:
- job: BuildAndPush
condition: or(eq(stageDependencies.Changed.Changes.outputs['detectChanges.anyServicesChanged'], true), eq(variables['Build.Reason'], 'Manual'))
displayName: Building and Push Docker images of services...
steps:
- ${{ each service in parameters.services }}:
- task: Docker@2
displayName: Build and Push ${{ service }} Docker image
inputs:
command: buildAndPush
repository: $(imageRepository)-${{ service }}
dockerfile: $(dockerfilePath)/${{ service }}/Dockerfile
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
${{ parameters.tag }}-${{ parameters.tagVersion }}

作业条件:完全相同,但这次它说它是NULL:

6 queue time variables used
Expanded: or(eq(Null, True), eq('PullRequest', 'Manual'))
Result: False

我不确定为什么会这样,因为我认为它会在我需要使用该变量的每个地方持续存在。

关于为什么会发生这种情况以及如何解决它的建议?

最佳答案

build.yaml中,您需要添加依赖于Changed阶段。否则,Changed阶段设置的变量在BuildAndPush阶段无法获取。

stages:
- stage: BuildAndPush
displayName: Build and Push Docker images of services...
condition: succeeded()
dependsOn:
- UnitTests
- Changed

关于azure - 作业条件在前一阶段使用后评估为 "null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66770056/

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