0

I've been tirelessly trying to make my pipeline work according to the

They claim that if I do the following step I should be able to access Name across multiple jobs:

pool:
  name: ubuntu

parameters:
- name: sourceArtifactPath
  type: string

jobs:
- job: Setup
  steps:
  - script: echo "##vso[task.setvariable variable=Name;isOutput=true]$(basename ${{ parameters.sourceArtifactPath }})"
    name: SetVariables
    displayName: "Set Pipeline Variables"
  - script: echo $(SetVariables.Name)

- job: DoStuff
  dependsOn: Setup
  steps:
  - bash: echo "Important work has beed done"

- job: Upload
  dependsOn: DoStuff
  variables:
    artifactName:  $[ dependencies.Setup.outputs['SetVariables.Name'] ]
  steps:
  - script: echo $(artifactName)
    displayName: "Print Filename"

and it works for the reference inside same job, however when I try to access Setup.SetVariables.Name from different job all im getting is:

==============================================================================
Generating script.
Script contents:
echo 
========================== Starting Command Output ===========================

please help.

some questions look similar but are not exactly the same like: 1 2

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Verthais
  • 300
  • 3
  • 14
  • I wasn't able to reproduce the issue using your YAML snippet, although I had to make a few indentation fixes (which I believe is the issue here). `artifactName` seems to print out in `Upload` job – Sibtain Feb 23 '23 at 14:28
  • I wish that was the case. Following you suggestion I auto-formatted the yaml, unfortunatelly nothing has change. – Verthais Feb 23 '23 at 14:39
  • Well it works for me, see [this](https://i.stack.imgur.com/9c8yt.png). Also, `name: ubuntu` is this a self hosted agent? – Sibtain Feb 23 '23 at 14:45
  • yes , it's 20.04 image on couple of build agent that are labeled as ubuntu – Verthais Feb 23 '23 at 14:50
  • Your YAML (pasted in the question) isn't valid. You might want to paste the YAML again. It's [not valid](https://i.stack.imgur.com/CRGH4.png). I am surprised how that even ran in ADO. – Sibtain Feb 23 '23 at 14:55

2 Answers2

1

Here is what worked for me. Important part is isOutput=true. Add this while defining variable otherwise you wont be able to view/print/echo the variable

trigger:
  branches:
    include:
      - 'master'
pool:
  mypool

jobs:
  # Set an output variable from job A
  - job: A
    steps:
    - script: |
        #!/bin/bash        
        echo "##vso[task.setvariable variable=myvar1;isOutput=true]True"
        echo "##vso[task.setvariable variable=myvar2;isOutput=true]hello"
      name: setvarStep
  # Map the variable into job B
  - job: B
    dependsOn: A
    variables:
      myVarFromJobA: $[ dependencies.A.outputs['setvarStep.myvar1'] ]  
      myVarFromJobA1: $[ dependencies.A.outputs['setvarStep.myvar2'] ]  
    steps:
    - script: echo $(myVarFromJobA)
      name: echovar
    - script: echo $(myVarFromJobA1)
      name: echovar1

0

If you want to reference a variable from the Setup job, you need to declare you're dependent on that job.

- job: Upload
  dependsOn: 
  - Setup
  - DoStuff

It's not enough to declare your job depends on DoStuff which declares its dependency on Setup.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • 1
    Yes, I've just discovered that and wanted to just write that. It's not written anywhere in the documentation which is infuriating to debug. – Verthais Feb 24 '23 at 10:09