Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps Pipeline: Pass Parameters to PowerShell-Inline-Task

How can I pass a parameter to a PowerShell-Inline-Task? Or how can I access the parameter in a PowerShell-Inline-Task? I know that there is the "$env"-Variable, and that I can read variables, but how is this done with parameters?

like image 528
etalon11 Avatar asked May 06 '26 09:05

etalon11


1 Answers

Tested from my side, I use parameters in PowerShell-Inline-Task as the following. The name of the parameter is "paratest", the type is string, the default value of it is one and also it has another value "two".

I get and output the value of the parameter in the PowerShell task using ${{ }}.

parameters:
  - name: paratest
    type: string
    default: one
    values: 
    - one
    - two

trigger:
- none

pool:
  vmImage: ubuntu-latest

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'Write-Host "The value of parameter paratest is ${{parameters.paratest}}"'

Before I run the pipeline, I can choose the value of the parameter "paratest".

enter image description here

Then I can see the value of this parameter in the PowerShell task. enter image description here

For more info about parameters, you can refer to Runtime parameters.

like image 149
Ziyang Liu-MSFT Avatar answered May 10 '26 03:05

Ziyang Liu-MSFT



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!