gpt4 book ai didi

azure - 如何在 azure 管道的不同阶段找到工作

转载 作者:行者123 更新时间:2023-12-02 23:00:43 29 4
gpt4 key购买 nike

我的 azure 管道中有类似的东西

pool:
name: name
vmImage: Image

stages:
stage: 1
jobs:
job: 1
job: 2
job: 3
stage: 2
condition: will run if stage 1 on job 2 is successful
stage: 3
condition: will run if job 1 or 3 in stage 1 is successful or stage
2 is successful

我可以在第一阶段获得工作 1 或 3 吗?或者我可以做一个

  (dependencies.stage3.job1.result,"Succeeded")

喜欢代码吗?

最佳答案

How to get a job on a different stage in azure pipeline

您可以为 job1job2job3 添加任务来为每个作业设置变量,例如:

  - task: InlinePowershell@1
displayName: 'SetVariableInJobA'
inputs:
Script: 'Write-Host "##vso[task.setvariable variable=JobA;isOutput=true]true"'
name: JobAResult

然后我们可以根据stage1中job1到job3的变量设置条件,语法为stageDependency.stageName.jobName.outputs['stepName.variableName']

请查看文档Jobs can access output variables from previous stages了解更多详细信息。

所以,我的最终测试 YAML 文件如下所示:

stages:
- stage: A
jobs:
- job: jobA
steps:
- script: echo "This is JobA"
- task: InlinePowershell@1
displayName: 'SetVariableInJobA'
inputs:
Script: 'Write-Host "##vso[task.setvariable variable=JobA;isOutput=true]true"'
name: JobAResult

- job: jobB
steps:
- script: echo "This is JobB"
- task: InlinePowershell@1
displayName: 'SetVariableInJobB'
inputs:
Script: 'Write-Host "##vso[task.setvariable variable=JobB;isOutput=true]No"'
name: JobBResult

- job: jobC
steps:
- script: echo "This is JobC"
- task: InlinePowershell@1
displayName: 'SetVariableInJobC'
inputs:
Script: 'Write-Host "##vso[task.setvariable variable=JobC;isOutput=true]true"'
name: JobCResult


- stage: B
variables:
testB: $[ stageDependencies.A.jobB.outputs['JobBResult.JobB']]

jobs:
- job:
condition: and(succeeded(), eq(variables.testB, 'Yes'))
steps:
- task: InlinePowershell@1
inputs:
Script: 'Write-Output ''$(testB)'''


- stage: C
variables:
testA: $[ stageDependencies.A.jobA.outputs['JobAResult.JobA']]
testB: $[ stageDependencies.A.jobB.outputs['JobBResult.JobB']]
testC: $[ stageDependencies.A.jobC.outputs['JobCResult.JobC']]
jobs:
- job:
condition: and(succeeded(), or(eq(variables.testA, 'Yes'), or(eq(variables.testB, 'Yes'), eq(variables.testC, 'Yes'))))
steps:
- task: InlinePowershell@1
inputs:
Script: 'Write-Output ''hello world'''

注意:

我们无法直接在stage级别设置条件,因为变量$[ stageDependency.A.jobA.outputs['JobAResult.JobA']]是编译变量,并且我们通过任务设置的变量是运行时变量。

关于azure - 如何在 azure 管道的不同阶段找到工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71029263/

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