1

I added the custom variable like this:

  - task: Bash@3
    displayName: 'naming the artifact'
    inputs:
      targetType: 'inline'
      script: |
        an=FE_SNAPSHOT.zip
        echo "##vso[task.setvariable variable=artifactName;]$an"

Now I am inside the deploy pipeline and would like to access the variable artifactName in a deploy bash script.

The variable is not listed in the "Initialize Job" step.

UPDATE 1: The deployment pipeline has a trigger to the build pipeline and the build pipeline is linked as an artifact (in the artifacts section). Maybe this is another problem...

SOLUTION: The linked ticket contains a part of my solution. The BUILD PIPELINE creates a simple file containing the value/variable I want to store:

  - task: Bash@3
    displayName: 'naming the artifact'
    inputs:
      targetType: 'inline'
      script: echo "FE_SNAPSHOT.zip" > $(Build.ArtifactStagingDirectory)/artifactName.value

The DEPLOYMENT PIPELINE reads the file and sets the variable:

  - task: Bash@3
    displayName: 'naming the artifact'
    inputs:
      targetType: 'inline'
      script: |
        an=`cat FE_CI_OS/drop/artifactName.value`
        echo "##vso[task.setvariable variable=artifactName;]${an}"

Then it can be used in a next task as $(artifactName).

eventhorizon
  • 2,977
  • 8
  • 33
  • 57
  • Also maybe this answer: https://stackoverflow.com/questions/52568195/how-to-get-the-variable-value-in-tfs-azuredevops-from-build-to-release-pipeline – Shayki Abramczyk Apr 28 '20 at 09:40

1 Answers1

0

Scope of this variable is a pipeline. And since this variable is set dynamically it it not listed in Initialize Job. It should be avaibale in your next task. Can you add right after this task

- script: echo $(artifactName)

You should get your value displayed.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • "Your build pipeline references an undefined variable named ‘artifactName’." – eventhorizon Apr 28 '20 at 08:42
  • Just another hint: "right after this task" would be in the build pipeline. I need the variable in the linked deployment pipeline! Maybe a misunderstanding!? – eventhorizon Apr 28 '20 at 08:46
  • So you want to set variable in build pipeline and reuse it in release pipeline right? Do you use mult-stage Yaml pipeline, or classic Release pipelines? – Krzysztof Madej Apr 28 '20 at 08:49