gpt4 book ai didi

azure - 在 Azure DevOps Pipelines 中不同阶段的步骤之间共享变量

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

我正在尝试弄清楚如何在管道中不同阶段的步骤之间共享自定义变量。我有三个管道,第一个管道查找存储库的更改,以查找任何更改并设置变量,然后在其他阶段的步骤中使用这些变量。我已经尝试了 dependency.Stage.outputs['Job.step.variable']stageDependency.Stage.Job.outputs['step.variable'] 但两者都尝试过给我错误,dependencystageDependency 是无法识别的值。我认为这是因为这些是阶段和作业级别的变量,无法在作业内部的步骤中访问。我如何才能访问这些变量?

我在子阶段和作业中有多个步骤,无论变量是否设置,都应该运行,这使得我不能只创建阶段或作业条件。

stages:
- stage: BuildAndUnit
jobs:
- job: Build
steps:
- task: touchify.vsts-changed-files.vsts-changed-files.ChangedFiles@1
displayName: 'Detect Changes'
inputs:
rules: |
[RunBackendTests]
!+(WebUi|Web2)/**
[RunNgWebAppTests]
Web2/*
Web2/!(administration)/**
[RunNgWebAdminTests]
Web2/package.json
Web2/package-lock.json
Web2/administration/**
- stage: CoreTests
displayName: 'Core Tests'
dependsOn: BuildAndUnit
jobs:
- job: CoreTest
steps:
- checkout: none
- task: Npm@1
displayName: 'Ng WebApp Unit Test'
inputs:
command: custom
customCommand: ''
condition: and(succeeded(), eq(stageDependencies.BuildAndUnit.Build.outputs['ChangedFiles.runngwebapptests'], 'true'))
- task: Npm@1
displayName: 'Run Ng WebAdmin Unit Tests'
inputs:
command: custom
customCommand: ''
condition: and(succeeded(), eq(stageDependencies.BuildAndUnit.Build.outputs['stageDependencies.BuildAndUnit.Build.outputs['ChangedFiles.runngwebadmintests'], 'true'))

最佳答案

我终于找到了!这是供将来寻找类似事物的人使用的,只需在工作级别导入变量即可。

stages:
- stage: BuildAndUnit
jobs:
- job: Build
steps:
- task: touchify.vsts-changed-files.vsts-changed-files.ChangedFiles@1
displayName: 'Detect Changes'
inputs:
rules: |
[RunBackendTests]
!+(WebUi|Web2)/**
[RunNgWebAppTests]
Web2/*
Web2/!(administration)/**
[RunNgWebAdminTests]
Web2/package.json
Web2/package-lock.json
Web2/administration/**
- stage: CoreTests
displayName: 'Core Tests'
dependsOn: BuildAndUnit
jobs:
- job: CoreTest
variables:
runngwebapptests: $[ stageDependencies.BuildAndUnit.Build.outputs['ChangedFiles.runngwebapptests'] ]
runngwebadmintests: $[ stageDependencies.BuildAndUnit.Build.outputs['ChangedFiles.runngwebadmintests'] ]
steps:
- checkout: none
- task: Npm@1
displayName: 'Ng WebApp Unit Test'
inputs:
command: custom
customCommand: ''
condition: and(succeeded(), eq(variables['runngwebapptests'], 'true'))
- task: Npm@1
displayName: 'Run Ng WebAdmin Unit Tests'
inputs:
command: custom
customCommand: ''
condition: and(succeeded(), eq(variables['runngwebadmintests'], 'true'))

关于azure - 在 Azure DevOps Pipelines 中不同阶段的步骤之间共享变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72621370/

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