0
votes

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?Levi Lu-MSFT

1 Answers

1
votes

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