azure devops - Access job output variables across stages with indirect dependencies - Stack Overflow

I have the following pipeline where stages execute in order A -> B -> C. Stage A creates an outpu

I have the following pipeline where stages execute in order A -> B -> C. Stage A creates an output variable that is used by stages B and C.

stages:
- stage: A
  isSkippable: false
  jobs:
  - job: A1
    steps:
    - checkout: none
    - pwsh: |
         write-host "##vso[task.setvariable variable=myOutput;isOutput=true]hello world"
      name: setVar
      displayName: create output variable

- stage: B
  dependsOn:
  - A
  variables:
    myOutput: $[ stageDependencies.A.A1.outputs["setVar.myOutput"] ]
  jobs:
  - job: B1
    steps:
    - checkout: none
    - pwsh: write-host "$(myOutput)"

- stage: C
  dependsOn:
  - B
  variables:
    myOutput: $[ stageDependencies.A.A1.outputs["setVar.myOutput"] ]
  jobs:
  - job: C1
    steps:
    - checkout: none
    - pwsh: write-host "$(myOutput)"

When the pipeline runs, the $(myOutput) variable in stage C isn't being populated. I would expect that because B depends on A, it's dependencies would be available to downstream dependencies (because C depends on B, and B depends on A, transitively C also depends on A).

How do I access job outputs of indirect dependencies?

I have the following pipeline where stages execute in order A -> B -> C. Stage A creates an output variable that is used by stages B and C.

stages:
- stage: A
  isSkippable: false
  jobs:
  - job: A1
    steps:
    - checkout: none
    - pwsh: |
         write-host "##vso[task.setvariable variable=myOutput;isOutput=true]hello world"
      name: setVar
      displayName: create output variable

- stage: B
  dependsOn:
  - A
  variables:
    myOutput: $[ stageDependencies.A.A1.outputs["setVar.myOutput"] ]
  jobs:
  - job: B1
    steps:
    - checkout: none
    - pwsh: write-host "$(myOutput)"

- stage: C
  dependsOn:
  - B
  variables:
    myOutput: $[ stageDependencies.A.A1.outputs["setVar.myOutput"] ]
  jobs:
  - job: C1
    steps:
    - checkout: none
    - pwsh: write-host "$(myOutput)"

When the pipeline runs, the $(myOutput) variable in stage C isn't being populated. I would expect that because B depends on A, it's dependencies would be available to downstream dependencies (because C depends on B, and B depends on A, transitively C also depends on A).

How do I access job outputs of indirect dependencies?

Share Improve this question asked Mar 24 at 22:45 bryanbcookbryanbcook 18.7k2 gold badges47 silver badges79 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I figured this out as I writing the question and sharing the results for you! I had assumed that if I included both dependencies in C, it would create a non-linear dependency graph where the path between A, B, and C would show an extra line between A and C.

The stageDependencies object is only populated with its direct dependencies, so to ensure that the outputs of A are available in C, C must declare a direct dependency to A.

- stage: C
  dependsOn:
  - A
  - B
  ...

Declaring both dependencies does not change the dependency graph. Azure DevOps is smart enough to figure out the transitive relationships.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744225080a4563965.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信