-1

I've attached a picture to this question and using this space to describe the steps highlighted.

  1. I have a main pipeline file that I run. I reference a template file, which executes as expected.
  2. Here is the template file.
  3. Here, I am setting the variable dynamically via PS (validated in my local session shown in 6.). I've tried setting it dynamically (commented out), but setting it manually for now for testing purposes.
  4. Back to the main pipeline, I'm looking to reference the value produced. NOTE: this screenshot shows this task being executed in a separate job, but I can shift this task to be in the same job, or switch to a different stage.
  5. Here is the output I receive.
  6. Here is the output I expect.

Thanks in advance!

Screenshot

2 Answers2

0

So from what I've looked at in the azure pipelines documentation, you should use the global expression.

Try doing this in the main pipeline:

- script:
  echo $(vmSize_SQLTDLT21DEV)

Let me know if it worked! ;)

  • Hi Nathan! Thanks for the response. I added this to my main pipeline: - task: CmdLine@2 displayName: 'Output vmSize Result' inputs: script: | echo $(SQLTDLT21_vmSize) Unfortunately the result yielded: Generating script. Script contents: shell echo $(SQLTDLT21_vmSize) "C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\agent\_work\_temp\498fb4cb-c972-4f8f-8b9d-980cd485838d.cmd"" **$(SQLTDLT21_vmSize)** Finishing: Output vmSize Result – Roshan Kumar Aug 21 '22 at 02:52
0

The Usage on you side is not correct.

UseVariableInTemplate.yml

trigger:
- none

pool:
  vmImage: ubuntu-latest

steps:
- template: setvariables.yml
  parameters:
    testparam: xxx

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.
      
      Write-Host "$(setvars.VMSize)"

setvariables.yml

parameters:
- name: testparam

steps:
- task: PowerShell@2
  name: setvars
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.
      
      Write-Host "Hello World"
      $testvars = "Standard_E8-2ds_v4" #Set variables here
      Write-Host "##vso[task.setvariable variable=VMSize;isOutput=true]$testvars"

Successfully on my side:

enter image description here

Please refer to this official document:

https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell

Bowman Zhu-MSFT
  • 4,776
  • 1
  • 9
  • 10