0

Hi All I'm working on ymal release pipeline where I have two PowerShell script. test1.ps1 test2.ps1

step 1) In test1.ps1 I'm setting a output variable using :

$link="google.com"

Write-Host "##vso[task.setvariable variable=packageurl]$link"

step 2) Now I want to use this pacakgeurl variable value in test2.ps1 script.

Ymal code will look like :

- task: AzurePowerShell@3

      displayName: 'Query Latest Package'

      inputs:
        azureSubscription: 'test1'
        ScriptType: FilePath
        ScriptPath: 'source\test1.ps1'

- task: PowerShell@2

      displayName: 'Download package' 
      inputs:
        targetType: filePath 
        filePath: 'source\test2.ps1'

So basically I have to use the output variable value from 1 task to 2 task via PowerShell script.

I also tried to follow this link : https://developercommunity.visualstudio.com/content/problem/676342/how-to-use-output-variable-from-a-powershell-scrip.html

Can anyone help me on this ..?

Thanks in advance.

1
  • How did you reference the variable in test2.ps1? Commented Dec 15, 2020 at 9:56

1 Answer 1

1

This works as you expect:


trigger: none
pr: none

pool:
  vmImage: 'windows-latest'


steps:
- task: AzurePowerShell@3
  displayName: 'Query Latest Package'

  inputs:
    azureSubscription: 'rg-the-code-manual'
    ScriptType: FilePath
    ScriptPath: 'stackoverflow\94-variables\script-1.ps1'
    azurePowerShellVersion: LatestVersion

- task: PowerShell@2
  displayName: 'Download package' 
  inputs:
    targetType: filePath 
    filePath: 'stackoverflow\94-variables\script-2.ps1'

Yaml file is as you have it.

script-1.ps1 sets variable:

$link="google.com"

Write-Host "##vso[task.setvariable variable=packageurl]$link"

And script-2.ps1 uses that variable:

Write-Host $env:PACKAGEURL
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.