I have a pipeline that is supposed to create a Azure subscription, to provide values I have set up a variable calld serviceConnection
:
jobs:
- job: Variables
displayName: 'Variables'
steps:
- checkout: self
- task: Bash@3
displayName: 'Get Json values and set output variables'
name: setOutput
inputs:
targetType: inline
script: |
serviceConnection=$(cat $(System.DefaultWorkingDirectory)/test/*.json | jq -r '.test.serviceConnection')
echo "##vso[task.setvariable variable=serviceConnection;isoutput=true]$serviceConnection"
- job: CreateSubscription
displayName: 'Create Subscription to Azure'
dependsOn: Variables
variables:
- name: serviceConnection
value: $[ dependencies.Variables.outputs['setOutput.serviceConnection'] ]
- task: AzureCLI@2
name: CreateSubscriptionCli
displayName: 'Create a subscription'
inputs:
azureSubscription: $(serviceConnection)
But when i start the pipeline i get this error:
"The pipeline is not valid. Job CreateSubscription: Step CreateSubscription input connectedServiceNameARM references service connection $(serviceConnection) which could not be found.
when i print out the variable it shows the value as intended.
using syntax:
${{ parameters.serviceConnection}}
i get similar error but with
$[ dependencies.Variables.outputs['setOutput.serviceConnection'] ]
2
Answers
I cannot say that I understand at all what you are trying to do…but: The input "azureSubscription" for the
AzureCLI@2
task, is a well-defined input which needs to reference an existing Azure DevOps Service Connection.From the YAML sample, you are using the cross-jobs variable to pass the service connection value.
The variable value will be set at runtime. But the Azure CLI task will read the azureSubscription Service connection value at compile time.
In this case, the variable
$(serviceConnection)
in Azure CLI task will not able to get value at compile time and show the error above.For more detailed info, you can refer to this doc about cross-jobs variables.
For a workaround, you can split the pipeline to two. One is used to get the service connection value in Json file. And then the first pipeline can trigger the second pipeline and pass the value to the second pipeline to run Azure CLI task.