I am trying to use an output variable in a second deployment job, by referencing it with ‘dependencies’, but it is not able to fetch the value. It seems that:
$[dependencies.FetchAppRegistration.outputs['Fetch_Azure_AD.AppClientId']]
does not return anything in the code below. I have tried to follow the guideline on
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash
without any luck. The pipeline output is:
FetchAppRegistration Console output:
Fetching Azure AD App with display name: msys-azure-dev
Application found. AppId: ***
Setting variable AppClientId to: ***
Deploy_Infrastructure Console output:
First Log:
echo "App Client ID: "
Second Log:
| Missing an argument for parameter 'existingAppClientId'. Specify a
| parameter of type 'System.String' and try again.
Full Code:
parameters:
environment: ''
serviceConnectionName: ''
jobs:
- job: Build
displayName: 'Build Job'
steps:
- script: echo "Building the application..."
displayName: 'Execute build'
- deployment: FetchAppRegistration
displayName: 'Fetch Azure AD App Registration Client ID'
environment: ${{ parameters.environment }}
dependsOn: Build
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: AzurePowerShell@5
name: Fetch_Azure_AD
displayName: 'Fetch Azure AD App Registration Client ID'
inputs:
azureSubscription: ${{ parameters.serviceConnectionName }}
ScriptType: 'InlineScript'
Inline: |
$appName = "msys-azure-${{ parameters.environment }}".ToLower()
Write-Host "Fetching Azure AD App with display name: $appName"
$app = Get-AzADApplication -DisplayName $appName
if ($app -eq $null) {
Write-Error "Application not found: $appName"
exit 1
}
$appId = $app.AppId
Write-Host "Application found. AppId: $appId"
Write-Host "##vso[task.setvariable variable=AppClientId;isOutput=true]$appId"
Write-Host "Setting variable AppClientId to: $appId"
azurePowerShellVersion: 'LatestVersion'
pwsh: true
- deployment: Deploy_Infrastructure
displayName: 'Deploy Infrastructure'
dependsOn: FetchAppRegistration
condition: succeeded()
environment: ${{ parameters.environment }}
variables:
AppClientId: $[dependencies.FetchAppRegistration.outputs['Fetch_Azure_AD.AppClientId']]
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: drop
displayName: Download artifacts
- script: |
echo "App Client ID: $(AppClientId)"
displayName: 'Debug App Client ID'
- task: AzurePowerShell@5
displayName: 'Deploy Azure Infrastructure'
inputs:
connectedServiceNameARM: ${{ parameters.serviceConnectionName }}
azurePowerShellVersion: 'LatestVersion'
ScriptPath: '$(Pipeline.Workspace)/drop/deploy/deploy.ps1'
ScriptArguments:
-resourceGroupName $(ResourceGroupName) `
-existingAppClientId $(AppClientId)