Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access YAML variable in inline PowerShell script

If I have a YAML Pipeline;

variables:
- name  : myVariable
  value : 'abcd'

and if I want to run some inline powershell - how can i access that value (abcd) in the powershell script;

I expected this to work - but it didnt;

- task: PowerShell@2
    displayName: "Do the thing"
    inputs:
      targetType: 'inline'
      script: 
        write-host $(myVariable)
like image 887
James Cooke Avatar asked May 08 '26 23:05

James Cooke


1 Answers

we could refer to this doc to specify variables at the pipeline, stage, or job level.

YAML build definition:

pool:
  vmImage: 'vs2017-win2016'

variables:
- name  : myVariable
  value : 'abcd'

steps:

- task: PowerShell@2
  displayName: "Do the thing"
  inputs:
    targetType: 'inline'
    script: 
      write-host $(myVariable)

Result:

enter image description here

like image 169
Vito Liu Avatar answered May 11 '26 13:05

Vito Liu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!