I have set a build variable which I would like to consume in my inline powershell script.
I tried $($myvariable) but this comes out blank.
Pass build variables to powerhshell inline script in Azure DevOps
To get the build variables with inline power shell script, you can try to use following syntax $env:variable:
$env:myvariable
The build variable:
The build result:
Note:At this moment, the value of nested variables (like $(myvariable$(Build.SourceBranchName))) on build variables table are not yet supported in the build pipelines.
Hope this helps.
here's what's working for me:
$(variableName)
for example built-in variable called Build.BuildNumber can be accessed like so:
$(Build.BuildNumber)
full example with format function:
- task: AzurePowerShell@3
displayName: UpdatePrereq
inputs:
azureSubscription: ${{ parameters.azureSubscription }}
ScriptType: InlineScript
Inline: |
${{ format('. $(Build.Repository.LocalPath)\scripts\_helpers.ps1
Update-DeploymentPrereq -resourceGroup {1} -location {3}
Update-Prereq -pathSuffix {0} -pathBase $(Build.Repository.LocalPath) -resourceGroup {1} -buildId $(Build.BuildNumber) -paramFile {2}
Update-DeploymentConcurrency -resourceGroup {1} -buildId $(Build.BuildNumber)',
parameters.buildDir, parameters.resourceGroupName, parameters.paramFile, parameters.location ) }}
azurePowerShellVersion: LatestVersion