Azure Pipelines allows for secret variables to be defined within the pipeline UI. The Microsoft docs say that, in order to use these variables in script tasks, they should be mapped to environment variables.
You need to map secret variable as environment variables to reference them in YAML pipelines. In this example, there are two secret variables defined in the UI, SecretOne and SecretTwo. The value of SecretOne is foo and the value of SecretTwo is bar
steps:
- powershell: |
Write-Host "My first secret variable is $env:FOO_ONE"
$env:FOO_ONE -eq "foo"
env:
FOO_ONE: $(SecretOne)
Unfortunately, the AzurePowerShell@5 task does not seem to expose an "env" property like the PowerShell@2 and Bash@3 tasks do. So how is one supposed to map secret pipeline variables into these tasks so that they can be referenced from inline scripts?
I had a look at the AzureCLI@2 task but it is also lacking the "env" property.
I found this SO question, but that only provides an answer for the PowerShell@2 task.
Note: The job running this step is executing on the Microsoft Hosted agent pool using the "windows-latest" VM image.
Unfortunately, the AzurePowerShell@5 task does not seem to expose an "env" property like the PowerShell@2 and Bash@3 tasks do
env
is one of the common properties that are supported by all tasks, including AzurePowerShell@5.
The following is valid:
- task: AzurePowerShell@5
inputs:
azureSubscription: 'my-subscription'
azurePowerShellVersion: LatestVersion
ScriptType: 'InlineScript'
Inline: |
Write-Host "Hello " + Env:FOO_ONE
env:
FOO_ONE: $(SecretOne)
See Task control options and environment variables for more details.