0

I am currently building a pipeline that will have a list of parameters, which will then pass those values to be used by child pipelines.

Main pipeline:

trigger: none

parameters:
  - {name: 'location', type: string, default: 'eastus2', values: ['eastus2', 'centralus'], displayName: 'Resource group location'}
  - {name: 'sqlDBAutoPauseDatabase', type: string, default: 'ooi', values: ['ooi', 'poembi'], displayName: 'SQL DB Autopause - Target database name'}
  - {name: 'sqlDBAutoPauseAction', type: string, default: 'Enable', values: ['Enable', 'Disable'], displayName: 'SQL DB Autopause - Action to perform'}
  - {name: 'sqlDBAutoPauseDelay', type: number, default: 60, values: [60, -1], displayName: 'SQL DB Autopause - Autopause delay time'}

stages:
- stage: 'Autopause'
  jobs:
  - template: '/cicd/pipelines/ooi/iac/ooi-sqldb-autopause.yaml'
    parameters:
      parent:
          ${{ insert }}: ${{ parameters }}

First child pipeline to run:

parameters:
  - {name: parent, type: object, default: {}}

jobs:
  - deployment: 'deploymentName'
    environment: 'OOI-${{parameters.parent.envName}}'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzurePowerShell@5
            inputs:
              azureSubscription: '$(ADO_Connection)'
              azurePowerShellVersion: 'LatestVersion'
              ScriptType: 'InlineScript'
              Inline: |
                Set-AzSqlDatabase `
                  -ResourceGroupName $(ResourceGroupName) `
                  -DatabaseName ${{parameters.parent.sqlDBAutoPauseDatabase}} `
                  -ServerName $(ServerShort) `
                  -AutoPauseDelayInMinutes ${{parameters.parent.sqlDBAutoPauseDelay}}

This works fine however, this means I would have to switch all the required pipelines I need to run to be a template file. I was wondering if there was another way to pass down these parameters to child pipelines? I've been looking into other options like variable groups and using the REST API.

1 Answer 1

1

Would recommend converting the parameters to a variable template file. The template would be loaded by each job template and remove parameters as let the job retrieve them. Unless you are going to need to override these said values based upon the job. If different for different environments can dynamically load the variable set.

Would be something like

envName_variables.yml:

variables:
  - {name: 'location', type: string, default: 'eastus2', values: ['eastus2', 'centralus'], displayName: 'Resource group location'}
  - {name: 'sqlDBAutoPauseDatabase', type: string, default: 'ooi', values: ['ooi', 'poembi'], displayName: 'SQL DB Autopause - Target database name'}
  - {name: 'sqlDBAutoPauseAction', type: string, default: 'Enable', values: ['Enable', 'Disable'], displayName: 'SQL DB Autopause - Action to perform'}
  - {name: 'sqlDBAutoPauseDelay', type: number, default: 60, values: [60, -1], displayName: 'SQL DB Autopause - Autopause delay time'}

And then your job templates:

  - deployment: 'deploymentName'
    environment: 'OOI-${{parameters.parent.envName}}'
    variables:
        - template: ${{parameters.parent.envName}_variables.yml
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzurePowerShell@5
            inputs:
              azureSubscription: '$(ADO_Connection)'
              azurePowerShellVersion: 'LatestVersion'
              ScriptType: 'InlineScript'
              Inline: |
                Set-AzSqlDatabase `
                  -ResourceGroupName $(ResourceGroupName) `
                  -DatabaseName ${{variables.sqlDBAutoPauseDatabase}} `
                  -ServerName $(ServerShort) `
                  -AutoPauseDelayInMinutes ${{variables.sqlDBAutoPauseDelay}}

This will also keep the variables scoped to just the instance of the job.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.