Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parametrize azureSubscription in azure devops template task

I am trying to use parameters in Azure Devops templates. I can print any parameter inside the template. But when I use parameter in a template with any task that requires azure subscription that will make the pipeline always fail with

"The pipeline is not valid. Job myDeployment: Step input azureSubscription references service connection $(mySubscription) which could not be found."

Example of pipeline and template below. Is there any way to path azure Subscription to the template?strong text

pipeline.yml

- stage: myStage
  pool: windows
  variables: 
    - name: azureSubscription
      value: mySubscription
    - name: keyVaultName
      name: myKeyVauld

  jobs: 
    deployment: myDeployment
    strategy: 
      runOnce:
        deploy:
          steps:
          - template: myTemplate.yml
            parameters: 
              subscription: $(azureSubscription) # changing this to literal will work but not what I need
              vault: $(keyVaultName)

myTemplate.yml

parameters:
- name: subscription
  type: string
  default: ''
- name: vault
  type: string
  default: ''

steps:

- task: AzureKeyVault@1
  inputs:
    azureSubscription: '${{ parameters.subscription }}'
    keyVaultName: '${{ parameters.vault }}'
    secretsFilter: myKey
like image 899
user1316502 Avatar asked Feb 27 '20 16:02

user1316502


People also ask

How do you pass variables between tasks in Azure DevOps?

Share variables between Tasks across the Jobs (of the same Stage) We need to use the isOutput=true flag when you desire to use the variable in another Task located in another Job. Navigate to Stage1_Job1_Task1 and add isoutput = true flag to the Logging Command which let's us to access the value outside the Job.

How do I deploy a previous release in Azure DevOps?

Open Project>Pipeline>Release>Select you CD pipeline and select last successful build and you can file redeploy option their.


1 Answers

This is a known issue / limitation. You have to pass the Azure subscription as a literal. No way around it that I know of, unfortunately.

It's been a point of discussion for literally years on this GitHub issue: https://github.com/microsoft/azure-pipelines-agent/issues/1307

like image 135
Daniel Mann Avatar answered Oct 19 '22 13:10

Daniel Mann