I have 6 different python srcipts. Each script deploys different resource to Azure and accepts different parameters. I would like to achieve this scenario:
I have a pipeline that will do the following:
- Ask which resource to deploy as I'm not always willing to deploy just one resource or all of them. I want to be able to choose.
- Ask to provide parameters depending on my choice from step 1.
- Deploy only resource selected in step 1.
So I have already created a pipeline in Azure Devops and it works fine (including integration with Git, it automatically installs python libraries, etc.) The problem is that I have to define parameters for all of my scripts in my yaml file and the list becomes long and messy. It's not very usefull when I know that I won't be deploying all resources. I have an example of my yaml file with just two resources to choose:
trigger:
- none
pool:
vmImage: ubuntu-latest
parameters:
- name: tenant_id
displayName: Tenant ID
type: string
default:
- name: SP_client_id
displayName: Service Principal Client ID
type: string
default:
- name: SP_client_secret
displayName: Service Principal Client secret
type: string
default:
- name: subscription
displayName: Subscription ID
type: string
default:
- name: dev_environment
displayName: Do you want to create a DEV environment?
type: boolean
default: True
- name: test_environment
displayName: Do you want to create a TEST environment?
type: boolean
default: True
- name: prod_environment
displayName: Do you want to create a PROD environment?
type: boolean
default: True
#################################################
- name: deploy_storage
displayName: "Deploy Storage?"
type: boolean
default: false
- name: storage_rg_name
displayName: Resource Group name.
type: string
default: 'abc'
- name: storage_name
displayName: Storage name.
type: string
default: 'abc'
- name: storage_location
displayName: Storage location
type: string
values:
- northeurope
- westeurope
default: 'northeurope'
- name: storage_sku
displayName: Storage SKU
type: string
values:
- 'Standard_LRS'
- 'Standard_GRS'
- 'Standard_RAGRS'
default: 'Standard_LRS'
- name: storage_kind
displayName: Storage kind
type: string
values:
- 'StorageV2'
- 'BlobStorage'
- 'FileStorage'
- 'BlockBlobStorage'
default: 'StorageV2'
- name: storage_hns
displayName: Enable HNS?
type: boolean
default: True
################################################################
- name: deploy_adf
displayName: "Deploy ADF?"
type: boolean
default: false
- name: adf_rg_name
displayName: Resource Group name. If does not exists, new one will be created.
type: string
default: your_resource_group_name
- name: adf_name
displayName: ADF name.
type: string
default: testowyadf
- name: adf_location
displayName: ADF location
type: string
values:
- northeurope
- westeurope
default: northeurope
- name: adf_ir_flag
displayName: Do you want to create a SHIR and save it's key in KeyVault?
type: boolean
default: False
- name: adf_shir_name
displayName: SHIR name. Leave blank if not applicable.
type: string
default:
- name: adf_secret_name
displayName: KV secret name. Leave blank if not applicable.
type: string
default:
- name: adf_keyvault_url
displayName: KeyVault URL. Leave blank if not applicable.
type: string
default:
stages:
- stage: SelectPipeline
displayName: "Select and Run Pipeline"
jobs:
- job: RunSelectedPipeline
steps:
# Logic to run Pipeline1
- ${{ if eq(parameters.deploy_storage, true) }}:
- template: MainPipelineTest_StoragePipeline.yml
parameters:
tenant: ${{ parameters.tenant_id }}
client_id: ${{ parameters.SP_client_id }}
client_secret: ${{ parameters.SP_client_secret }}
subscription: ${{ parameters.subscription }}
storage_rg_name: ${{ parameters.storage_rg_name }}
storage_name: ${{ parameters.storage_name }}
storage_location: ${{ parameters.storage_location }}
storage_sku: ${{ parameters.storage_sku }}
storage_kind: ${{ parameters.storage_kind }}
storage_hns: ${{ parameters.storage_hns }}
dev_environment: ${{ parameters.dev_environment }}
test_environment: ${{ parameters.test_environment }}
prod_environment: ${{ parameters.prod_environment }}
- ${{ if eq(parameters.deploy_adf, true) }}:
- template: MainPipelineTest_ADFPipeline.yml
parameters:
tenant: ${{ parameters.tenant_id }}
client_id: ${{ parameters.SP_client_id }}
client_secret: ${{ parameters.SP_client_secret }}
subscription: ${{ parameters.subscription }}
adf_rg_name: ${{ parameters.adf_rg_name }}
adf_name: ${{ parameters.adf_name }}
adf_location: ${{ parameters.adf_location }}
adf_ir_flag: ${{ parameters.adf_ir_flag }}
adf_shir_name: ${{ parameters.adf_shir_name }}
adf_secret_name: ${{ parameters.adf_secret_name }}
adf_keyvault_url: ${{ parameters.adf_keyvault_url }}
dev_environment: ${{ parameters.dev_environment }}
test_environment: ${{ parameters.test_environment }}
prod_environment: ${{ parameters.prod_environment }}
Is there a way to make it more dynamic? So it will ask for parameters only for selected resources? Maybe there is different approach than Azure Devops for that?
Thanks in advance.
I have 6 different python srcipts. Each script deploys different resource to Azure and accepts different parameters. I would like to achieve this scenario:
I have a pipeline that will do the following:
- Ask which resource to deploy as I'm not always willing to deploy just one resource or all of them. I want to be able to choose.
- Ask to provide parameters depending on my choice from step 1.
- Deploy only resource selected in step 1.
So I have already created a pipeline in Azure Devops and it works fine (including integration with Git, it automatically installs python libraries, etc.) The problem is that I have to define parameters for all of my scripts in my yaml file and the list becomes long and messy. It's not very usefull when I know that I won't be deploying all resources. I have an example of my yaml file with just two resources to choose:
trigger:
- none
pool:
vmImage: ubuntu-latest
parameters:
- name: tenant_id
displayName: Tenant ID
type: string
default:
- name: SP_client_id
displayName: Service Principal Client ID
type: string
default:
- name: SP_client_secret
displayName: Service Principal Client secret
type: string
default:
- name: subscription
displayName: Subscription ID
type: string
default:
- name: dev_environment
displayName: Do you want to create a DEV environment?
type: boolean
default: True
- name: test_environment
displayName: Do you want to create a TEST environment?
type: boolean
default: True
- name: prod_environment
displayName: Do you want to create a PROD environment?
type: boolean
default: True
#################################################
- name: deploy_storage
displayName: "Deploy Storage?"
type: boolean
default: false
- name: storage_rg_name
displayName: Resource Group name.
type: string
default: 'abc'
- name: storage_name
displayName: Storage name.
type: string
default: 'abc'
- name: storage_location
displayName: Storage location
type: string
values:
- northeurope
- westeurope
default: 'northeurope'
- name: storage_sku
displayName: Storage SKU
type: string
values:
- 'Standard_LRS'
- 'Standard_GRS'
- 'Standard_RAGRS'
default: 'Standard_LRS'
- name: storage_kind
displayName: Storage kind
type: string
values:
- 'StorageV2'
- 'BlobStorage'
- 'FileStorage'
- 'BlockBlobStorage'
default: 'StorageV2'
- name: storage_hns
displayName: Enable HNS?
type: boolean
default: True
################################################################
- name: deploy_adf
displayName: "Deploy ADF?"
type: boolean
default: false
- name: adf_rg_name
displayName: Resource Group name. If does not exists, new one will be created.
type: string
default: your_resource_group_name
- name: adf_name
displayName: ADF name.
type: string
default: testowyadf
- name: adf_location
displayName: ADF location
type: string
values:
- northeurope
- westeurope
default: northeurope
- name: adf_ir_flag
displayName: Do you want to create a SHIR and save it's key in KeyVault?
type: boolean
default: False
- name: adf_shir_name
displayName: SHIR name. Leave blank if not applicable.
type: string
default:
- name: adf_secret_name
displayName: KV secret name. Leave blank if not applicable.
type: string
default:
- name: adf_keyvault_url
displayName: KeyVault URL. Leave blank if not applicable.
type: string
default:
stages:
- stage: SelectPipeline
displayName: "Select and Run Pipeline"
jobs:
- job: RunSelectedPipeline
steps:
# Logic to run Pipeline1
- ${{ if eq(parameters.deploy_storage, true) }}:
- template: MainPipelineTest_StoragePipeline.yml
parameters:
tenant: ${{ parameters.tenant_id }}
client_id: ${{ parameters.SP_client_id }}
client_secret: ${{ parameters.SP_client_secret }}
subscription: ${{ parameters.subscription }}
storage_rg_name: ${{ parameters.storage_rg_name }}
storage_name: ${{ parameters.storage_name }}
storage_location: ${{ parameters.storage_location }}
storage_sku: ${{ parameters.storage_sku }}
storage_kind: ${{ parameters.storage_kind }}
storage_hns: ${{ parameters.storage_hns }}
dev_environment: ${{ parameters.dev_environment }}
test_environment: ${{ parameters.test_environment }}
prod_environment: ${{ parameters.prod_environment }}
- ${{ if eq(parameters.deploy_adf, true) }}:
- template: MainPipelineTest_ADFPipeline.yml
parameters:
tenant: ${{ parameters.tenant_id }}
client_id: ${{ parameters.SP_client_id }}
client_secret: ${{ parameters.SP_client_secret }}
subscription: ${{ parameters.subscription }}
adf_rg_name: ${{ parameters.adf_rg_name }}
adf_name: ${{ parameters.adf_name }}
adf_location: ${{ parameters.adf_location }}
adf_ir_flag: ${{ parameters.adf_ir_flag }}
adf_shir_name: ${{ parameters.adf_shir_name }}
adf_secret_name: ${{ parameters.adf_secret_name }}
adf_keyvault_url: ${{ parameters.adf_keyvault_url }}
dev_environment: ${{ parameters.dev_environment }}
test_environment: ${{ parameters.test_environment }}
prod_environment: ${{ parameters.prod_environment }}
Is there a way to make it more dynamic? So it will ask for parameters only for selected resources? Maybe there is different approach than Azure Devops for that?
Thanks in advance.
Share Improve this question asked Mar 5 at 19:42 KingWolinKingWolin 231 silver badge5 bronze badges2 Answers
Reset to default 0it will ask for parameters only for selected resources
This essentially determines whether to expand other parameters based on the value of one parameter. However, it's not supported in Azure DevOps currently. All parameters will be expanded at template parsing time, just before the pipeline runs.
If you want such a feature, you can submit a feature request on Azure DevOps Developer Community.
If you have a lot of parameters and the templates for deploying different resources do not affect each other, I suggest you create independent pipelines for different resources, or put resources that are often deployed together into one pipeline.
So it will ask for parameters only for selected resources
It is not possible at the moment.
If many of your parameters are constant, you can use variables templates here. You can check var template here
credential-var.yml
variables:
- name: tenant_id
value: 'xxxx'
- name: SP_client_id
value: 'xxxx'
- name: SP_client_secret
value: 'xxxx'
- name: subscription
value: 'xxxx'
sa.yml
variables:
- name: sa_name
value: 'xxxx'
- name: sa_rg_name
value: 'xxxx'
azure-devops-pipeline.yml
parameters:
- name: name
type: string
default: ''
variables:
- template: variables-template.yml
- template: sa.yml
stages:
- stage: ${{ parameters.name }}
jobs:
- job: Build
steps:
- script: |
echo $(tenant_id)
- script: |
echo $(sa_name)
...