Skip to content

Instantly share code, notes, and snippets.

@nielsvanderkaap
Last active September 4, 2021 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielsvanderkaap/a3a299e9a833fb0e2555b1af190e59cd to your computer and use it in GitHub Desktop.
Save nielsvanderkaap/a3a299e9a833fb0e2555b1af190e59cd to your computer and use it in GitHub Desktop.
parameters:
- name: config
type: object
- name: buildVariableGroups
type: object
default: []
- name: components
type: object
default: []
- name: deployVariableGroups
type: object
default: []
- name: environments
type: object
default:
- name: DEV
azureServiceConnection: '<dev serviceconnectino>'
- name: TST
azureServiceConnection: '<tst serviceconnectino>'
dependsOn:
- Development
- name: UAT
azureServiceConnection: '<uat serviceconnectino>'
condition: eq(variables['Build.SourceBranchName'], 'main')
dependsOn:
- Test
- name: Prd
azureServiceConnection: '<prd serviceconnection>'
condition: eq(variables['Build.SourceBranchName'], 'main')
dependsOn:
- UAT
variables:
- name: basePath
value: $(Build.Repository.LocalPath)/${{parameters.config.basePath}}
- ${{ each variableGroup in parameters.buildVariableGroups }}:
- group: variableGroup
stages:
- ${{if eq(parameters.config.isBuild, true)}}:
### BUILD STAGE ###
- stage: Build
jobs:
# PIPELINERESOURCES
- job: PublishPipelineResources
displayName: Publish pipeline resources as artifact
steps:
- task: PublishPipelineArtifact@1
displayName: Publish pipeline artifacts for further consumption
inputs:
targetPath: '$(Build.Repository.LocalPath)/pipelines/Template.v1/Resources'
artifact: 'Pipeline'
publishLocation: 'pipeline'
- ${{ each component in parameters.components }}:
- job:
displayName: 'Build - ${{component.displayname}}'
steps:
- template: ${{component.type}}.build.yml
parameters:
component: ${{component}}
### DEPLOY STAGES ###
- ${{if eq(parameters.config.isDeploy, true)}}:
- ${{ each environment in parameters.environments }}:
- stage: Deploy_${{environment.name}}
displayName: Deploy - ${{environment.name}}
dependsOn:
- ${{ each dependency in environment.dependsOn }}:
- Deploy_${{dependency}}
${{if and(ne(environment.condition, ''), eq(parameters.config.environment, 'All'))}}:
condition: and(succeeded(), ${{environment.condition}})
${{if and(eq(environment.condition, ''), eq(parameters.config.environment, 'All'))}}:
condition: succeeded()
${{if and(ne(environment.condition, ''), ne(parameters.config.environment, 'All'))}}:
condition: and(eq('${{parameters.config.environment}}', '${{environment.name}}'), ${{environment.condition}})
${{if and(eq(environment.condition, ''), ne(parameters.config.environment, 'All'))}}:
condition: eq('${{parameters.config.environment}}', '${{environment.name}}')
variables:
- group: Infra.${{environment.name}}
- ${{ each variableGroup in parameters.deployVariableGroups }}:
- group: variableGroup${{environment.name}}
jobs:
- ${{ each component in parameters.components }}:
- deployment: Deploy_${{component.name}}
displayName: Deploy ${{component.displayName}}
environment: ${{environment.name}}
strategy:
runOnce:
deploy:
steps:
- template: ${{component.type}}.deploy.yml
parameters:
component: ${{component}}
environment: ${{environment}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment