I have below code in yaml file:
trigger:
branches:
include:
- maventest
pool:
vmImage: ubuntu-latest
steps:
- task: PowerShell@2
inputs:
filePath: './1.ps1'
Below is 1.ps1 file
$user1=@($(user))
Write-Host $(user)
write-host $user1[0]
As I can pass the value of variable inside while run pipeline but user is not getting from variable.
I had also used the $(env:user) but it didn't get value from variable.
CodePudding user response:
From your YAML sample, the cause of the issue is that the pipeline variable is not able to directly expand in PowerShell file.
To solve this issue, you can pass the pipeline variable to ps file via argument of PowerShell task.
Here is the example:
Ps file sample:
param($user)
$user1=@($user)
Write-Host $user
write-host $user1[0]
Pipeline sample:
steps:
- task: PowerShell@2
inputs:
filePath: './1.ps1'
arguments: '-user $(user)'
Result: