Azure 管道,分支出工作但无法在批准后返回分支
Azure pipeline, branching out works but unable to branch back in after approval
我正在 运行 在 Windows 自托管代理上构建管道。
我使用一个脚本在一个阶段初始化一个变量,然后在接下来的两个阶段在条件中使用该变量。
如果变量为真,则第三阶段为运行,此阶段为具有批准的环境。
如果变量为假,第四阶段为运行。
无论如何,第五阶段必须总是运行。
我的 YAML 工作到第五阶段,它会 运行 只有当第四阶段是 运行 !!
这是我的 Yaml:
stages:
- stage: Init
jobs:
- job: RunScript
steps:
- checkout: none
- task: PowerShell@2
name: compareFiles
inputs:
targetType: filePath
filePath: '***\compareFileContent.ps1'
- stage: Display1
dependsOn: Init
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- job: DisplayVariables
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo areFilesDifferent: $(areFilesDifferent)
- stage: WithApproval
dependsOn: Display1
condition: eq( dependencies.Init.outputs['RunScript.compareFiles.areDifferent'], 'false' )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- deployment: DeploymentJob
environment: 'STWithApproval'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo DeploymentStageWithApproval: $(areFilesDifferent)
- job: SetupNext
dependsOn: DeploymentJob
steps:
- checkout: none
- task: PowerShell@2
name: setupNext
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=continue;isOutput=true]yes"
- stage: WithoutApproval
dependsOn: Display1
condition: eq( dependencies.Init.outputs['RunScript.compareFiles.areDifferent'], 'true' )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- deployment: DeploymentJob
environment: 'ST'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo DeploymentStageWithoutApproval: $(areFilesDifferent)
- job: SetupNext
dependsOn: DeploymentJob
steps:
- checkout: none
- task: PowerShell@2
name: setupNext
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=continue;isOutput=true]yes"
- stage: Display2
condition: xor( eq( dependencies.WithApproval.outputs['SetupNext.setupNext.continue'], 'yes' ), eq( dependencies.WithoutApproval.outputs['SetupNext.setupNext.continue'], 'yes' ) )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
WithApproval: $[ stageDependencies.WithApproval.SetupNext.outputs['setupNext.continue'] ]
WithoutApproval: $[ stageDependencies.WithoutApproval.SetupNext.outputs['setupNext.continue'] ]
jobs:
- job: DisplayVariables
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo areFilesDifferent: $(areFilesDifferent)
echo WithApproval: $(WithApproval)
echo WithoutApproval: $(WithoutApproval)
如果 WithApproval 运行s,则跳过 Display2 !!
??
If WithoutApproval 运行s, Display2 运行s 但不会显示areFilesDifferent
的内容
我尝试在 Display2 中测试 WithApproval 或 WithoutApproval 运行 是否成功,但由于它不起作用,我尝试设置那些 'continue' 变量,但这不是我最喜欢的方法。
是否可以在等待批准后b运行ch回到Display2?
感谢您的任何建议,
克劳德
我明白了。
为了构建依赖关系图,它使用 DependsOn 语句,为了访问前一阶段的输出变量,阶段名称必须出现在 DependsOn 语句中,如此 YAML 和图片所示:
stages:
- stage: Build
jobs:
- job: CompareFiles
dependsOn: Build_Project
steps:
- checkout: none
- task: PowerShell@2
name: compareFiles
inputs:
targetType: filePath
filePath: '***\compareFileContent.ps1'
- stage: ContinueWithApproval
dependsOn: Build
condition: eq( dependencies.Build.outputs['CompareFiles.compareFiles.filesAreEqual'], 'true' )
jobs:
- deployment: Continue
environment: 'EnvironmentWithApproval'
strategy:
runOnce:
deploy:
steps:
- task: CmdLine@2
inputs:
script: '***'
- stage: ContinueWithoutApproval
dependsOn: Build
condition: eq( dependencies.Build.outputs['CompareFiles.compareFiles.filesAreEqual'], 'false' )
jobs:
- deployment: Continue
environment: 'EnvironmentWithoutApproval'
strategy:
runOnce:
deploy:
steps:
- task: CmdLine@2
inputs:
script: '***'
- stage: DeployStaging
dependsOn:
- ContinueWithApproval
- ContinueWithoutApproval
condition: or(eq( dependencies.ContinueWithApproval.result, 'Succeeded' ), eq( dependencies.ContinueWithoutApproval.result, 'Succeeded' ))
jobs:
- deployment: Deploy_To_Staging
environment: 'Name ST'
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
inputs:
targetType: filePath
filePath: '***.ps1'
- stage: DeployPreProd
dependsOn:
- DeployStaging
jobs:
- deployment: Deploy_To_Preprod
environment: 'Name PP'
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
inputs:
targetType: filePath
filePath: '***.ps1'
现在,我遇到了另一个问题,跳过了最后一个阶段,但那是另一回事了...:-)
此致,
克劳德
我正在 运行 在 Windows 自托管代理上构建管道。 我使用一个脚本在一个阶段初始化一个变量,然后在接下来的两个阶段在条件中使用该变量。
如果变量为真,则第三阶段为运行,此阶段为具有批准的环境。
如果变量为假,第四阶段为运行。
无论如何,第五阶段必须总是运行。
我的 YAML 工作到第五阶段,它会 运行 只有当第四阶段是 运行 !!
这是我的 Yaml:
stages:
- stage: Init
jobs:
- job: RunScript
steps:
- checkout: none
- task: PowerShell@2
name: compareFiles
inputs:
targetType: filePath
filePath: '***\compareFileContent.ps1'
- stage: Display1
dependsOn: Init
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- job: DisplayVariables
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo areFilesDifferent: $(areFilesDifferent)
- stage: WithApproval
dependsOn: Display1
condition: eq( dependencies.Init.outputs['RunScript.compareFiles.areDifferent'], 'false' )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- deployment: DeploymentJob
environment: 'STWithApproval'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo DeploymentStageWithApproval: $(areFilesDifferent)
- job: SetupNext
dependsOn: DeploymentJob
steps:
- checkout: none
- task: PowerShell@2
name: setupNext
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=continue;isOutput=true]yes"
- stage: WithoutApproval
dependsOn: Display1
condition: eq( dependencies.Init.outputs['RunScript.compareFiles.areDifferent'], 'true' )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- deployment: DeploymentJob
environment: 'ST'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo DeploymentStageWithoutApproval: $(areFilesDifferent)
- job: SetupNext
dependsOn: DeploymentJob
steps:
- checkout: none
- task: PowerShell@2
name: setupNext
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=continue;isOutput=true]yes"
- stage: Display2
condition: xor( eq( dependencies.WithApproval.outputs['SetupNext.setupNext.continue'], 'yes' ), eq( dependencies.WithoutApproval.outputs['SetupNext.setupNext.continue'], 'yes' ) )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
WithApproval: $[ stageDependencies.WithApproval.SetupNext.outputs['setupNext.continue'] ]
WithoutApproval: $[ stageDependencies.WithoutApproval.SetupNext.outputs['setupNext.continue'] ]
jobs:
- job: DisplayVariables
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo areFilesDifferent: $(areFilesDifferent)
echo WithApproval: $(WithApproval)
echo WithoutApproval: $(WithoutApproval)
如果 WithApproval 运行s,则跳过 Display2 !! ??
If WithoutApproval 运行s, Display2 运行s 但不会显示areFilesDifferent
的内容我尝试在 Display2 中测试 WithApproval 或 WithoutApproval 运行 是否成功,但由于它不起作用,我尝试设置那些 'continue' 变量,但这不是我最喜欢的方法。
是否可以在等待批准后b运行ch回到Display2?
感谢您的任何建议, 克劳德
我明白了。 为了构建依赖关系图,它使用 DependsOn 语句,为了访问前一阶段的输出变量,阶段名称必须出现在 DependsOn 语句中,如此 YAML 和图片所示:
stages:
- stage: Build
jobs:
- job: CompareFiles
dependsOn: Build_Project
steps:
- checkout: none
- task: PowerShell@2
name: compareFiles
inputs:
targetType: filePath
filePath: '***\compareFileContent.ps1'
- stage: ContinueWithApproval
dependsOn: Build
condition: eq( dependencies.Build.outputs['CompareFiles.compareFiles.filesAreEqual'], 'true' )
jobs:
- deployment: Continue
environment: 'EnvironmentWithApproval'
strategy:
runOnce:
deploy:
steps:
- task: CmdLine@2
inputs:
script: '***'
- stage: ContinueWithoutApproval
dependsOn: Build
condition: eq( dependencies.Build.outputs['CompareFiles.compareFiles.filesAreEqual'], 'false' )
jobs:
- deployment: Continue
environment: 'EnvironmentWithoutApproval'
strategy:
runOnce:
deploy:
steps:
- task: CmdLine@2
inputs:
script: '***'
- stage: DeployStaging
dependsOn:
- ContinueWithApproval
- ContinueWithoutApproval
condition: or(eq( dependencies.ContinueWithApproval.result, 'Succeeded' ), eq( dependencies.ContinueWithoutApproval.result, 'Succeeded' ))
jobs:
- deployment: Deploy_To_Staging
environment: 'Name ST'
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
inputs:
targetType: filePath
filePath: '***.ps1'
- stage: DeployPreProd
dependsOn:
- DeployStaging
jobs:
- deployment: Deploy_To_Preprod
environment: 'Name PP'
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
inputs:
targetType: filePath
filePath: '***.ps1'
现在,我遇到了另一个问题,跳过了最后一个阶段,但那是另一回事了...:-)
此致, 克劳德