Adding Azure Subscription as a Parameter of Task Group in VSTS
You can use variable in Azure Subscription, but the value should be the actual value of related endpoint.
- Create a new release/build definition with debug enabled (set/add
system.debug
variable totrue
) and add Azure PowerShell task to get the actual value. - Start/Queue release/build, then check the log, you can find the log like this: ##[debug]INPUT_CONNECTEDSERVICENAMEARM: '{actual value}’
- Edit task group, specify variable in Azure Subscription input box (e.g.
$(sub)
) >Save - Edit your release definition, add the variable(s) (e.g.
mySub
) with that actual value (step 1) - Tasks > Select related Task group > Specify variable (e.g.
$(mySub)
) insub
(per to step 3) input box.
On the other hand, you can choose azure subscription for related task group directly (step 3, then edit tasks for an environment > Choose Azure Subscription directly)
While there are examples out there that suggest you can use a variable for the service connection name, there is also some documentation out there that suggests that variables for service connections are not supported (https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#use-a-service-connection, for example).
I've run up against this in my own pipelines and solved it using template expressions:
${{ if eq(parameters.environmentType, 'dev') }}: azureResourceManagerConnection: Azure Dev ${{ if eq(parameters.environmentType, 'test') }}: azureResourceManagerConnection: Azure Test ${{ if eq(parameters.environmentType, 'prod') }}: azureResourceManagerConnection: Azure Prod