When I mark pipeline variable (Pipeline -> Library) as secret, I cannot able to use it in my pipeline runs.
In Pipeline, I am trying to pass the secret variable to PowerShell script. But it always show as empty.
I have mapped the secret variable to Task environment. But it still shows as empty.
Powershell:
param (
$Secret = $Env:SECRET_VAR
)
...
Yaml Task:
- task: PowerShell@2
displayName: 'Post Restquest'
inputs:
targetType: filePath
filePath: ./PostRequest.ps1
env:
SECRET_VAR: $(token)
Test the same YAML sample and I can reproduce the same issue.
The cause of the issue can be that the prefix: SECRET of the environment variable name.
If the mapped environment variable in task is using SECRET as prefix, the environment variable will show as empty value.
To solve this issue, you need to change the environment name prefix(Avoid using SECRET).
For example: Change SECRET_VAR
-> MAPPED_VAR
YAML sample:
- task: PowerShell@2
displayName: 'Post Restquest'
inputs:
targetType: filePath
filePath: ./PostRequest.ps1
env:
MAPPED_VAR: $(token)
PowerShell script:
param (
$Secret = $Env:MAPPED_VAR
)
echo $Secret
Result: