Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Azure DevOps Pipelines Refactoring Technics
# pipeline.yaml
...
stages:
...
- stage: BuildWithJobsTemplate
displayName: 'Build with Jobs Template'
variables:
- name: Greeting
value: 'Hello World'
jobs:
- template: 'template-jobs-build.yaml'
parameters:
vmImage: 'vs2017-win2016'
message: 'This is from the jobs template'
...
# pipeline.yaml
...
variables:
- name: Greeting
value: "G'day, mate"
...
stages:
...
- template: 'template-stages-nested-build.yaml'
parameters:
vmImage: 'macOS-10.13'
message: 'This is from the nested stages template'
...
# pipeline.yaml
...
variables:
- name: Greeting
value: "G'day, mate"
...
stages:
...
- template: 'template-stages-build.yaml'
parameters:
vmImage: 'ubuntu-16.04'
message: 'This is from the stages template'
...
# pipeline.yaml
...
stages:
...
- stage: BuildWithStepsTemplate
displayName: 'Build with Steps Template'
jobs:
- job: HostedVs2017
displayName: 'Hosted VS2017'
pool:
name: 'Hosted VS2017'
workspace:
clean: all
variables:
- name: Greeting
value: 'Hello World'
steps:
- template: 'template-steps-build.yaml'
parameters:
message: 'This is from the steps template'
...
# pipeline.yaml
...
stages:
...
- stage: BuildWithoutTemplate
displayName: 'Build without Template'
jobs:
- job: HostedVs2017
displayName: 'Hosted VS2017'
pool:
name: 'Hosted VS2017'
workspace:
clean: all
variables:
- name: Greeting
value: 'Hello World'
steps:
- task: PowerShell@2
displayName: 'Echo Greeting in PowerShell'
inputs:
targetType: Inline
script: 'Write-Host "$(Greeting)"'
...
# pipeline.yaml
...
stages:
...
- stage: ReleaseWithJobsTemplate
displayName: 'Release with Jobs Template'
variables:
- name: Greeting
value: 'Hello World'
jobs:
- template: 'template-jobs-release.yaml'
parameters:
templateLevel: jobs
vmImage: 'vs2017-win2016'
message: 'This is from the jobs template'
...
# pipeline.yaml
...
stages:
...
- template: 'template-stages-nested-release.yaml'
parameters:
templateLevel: nested-stages
vmImage: 'macOS-10.13'
message: 'This is from the nested stages template'
...
# pipeline.yaml
...
stages:
...
- template: 'template-stages-release.yaml'
parameters:
templateLevel: stages
vmImage: 'ubuntu-16.04'
message: 'This is from the stages template'
...
# pipeline.yaml
...
stages:
...
- stage: ReleaseWithStepsTemplate
displayName: 'Release with Steps Template'
jobs:
- deployment: HostedVs2017
displayName: 'Hosted VS2017'
pool:
name: 'Hosted VS2017'
environment: release-with-steps-template
variables:
- name: Greeting
value: 'Hello World'
strategy:
runOnce:
deploy:
steps:
- template: 'template-steps-release.yaml'
parameters:
message: 'This is from the steps template'
...
# pipeline.yaml
...
stages:
...
- stage: ReleaseWithoutTemplate
displayName: 'Release without Template'
jobs:
- deployment: HostedVs2017
displayName: 'Hosted VS2017'
pool:
name: 'Hosted VS2017'
environment: release-without-template
variables:
- name: Greeting
value: 'Hello World'
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
displayName: 'Echo Greeting in PowerShell'
inputs:
targetType: Inline
script: 'Write-Host "$(Greeting)"'
...
# template-jobs-build.yaml
parameters:
vmImage: ''
message: ''
jobs:
- job: TemplatedJob
displayName: 'Templated Job'
pool:
vmImage: '${{ parameters.vmImage }}'
workspace:
clean: all
steps:
- task: PowerShell@2
displayName: 'Echo Greeting in PowerShell'
inputs:
targetType: Inline
script: |
Write-Host "$(Greeting)"
Write-Host "${{ parameters.message }}"
# template-jobs-nested-build.yaml
parameters:
vmImage: ''
message: ''
jobs:
- job: NestedBuildJob
displayName: 'Nested Build Job on ${{ parameters.vmImage }}'
pool:
vmImage: '${{ parameters.vmImage }}'
workspace:
clean: all
steps:
- template: 'template-steps-build.yaml'
parameters:
message: '${{ parameters.message }}'
# template-jobs-nested-release.yaml
parameters:
templateLevel: ''
vmImage: ''
message: ''
jobs:
- deployment: NestedDeploymentJob
displayName: 'Nested Deployment Job on ${{ parameters.vmImage }}'
pool:
vmImage: '${{ parameters.vmImage }}'
environment: release-with-${{ parameters.templateLevel }}-template
strategy:
runOnce:
deploy:
steps:
- template: 'template-steps-release.yaml'
parameters:
message: '${{ parameters.message }}'
# template-jobs-release.yaml
parameters:
templateLevel: ''
vmImage: ''
message: ''
jobs:
- deployment: TemplatedRelease
displayName: 'Templated Release'
pool:
vmImage: '${{ parameters.vmImage }}'
environment: release-with-${{ parameters.templateLevel }}-template
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
displayName: 'Echo Greeting in PowerShell'
inputs:
targetType: Inline
script: |
Write-Host "$(Greeting)"
Write-Host "${{ parameters.message }}"
# template-stages-build.yaml
parameters:
vmImage: ''
message: ''
stages:
- stage: BuildWithStagesTemplate
displayName: 'Build with Stages Template'
jobs:
- job: TemplatedStage
displayName: 'Templated Stage'
pool:
vmImage: '${{ parameters.vmImage }}'
workspace:
clean: all
steps:
- task: PowerShell@2
displayName: 'Echo Greeting in PowerShell'
inputs:
targetType: Inline
script: |
Write-Host "$(Greeting)"
Write-Host "${{ parameters.message }}"
# template-stages-nested-build.yaml
parameters:
vmImage: ''
message: ''
stages:
- stage: BuildWithNestedStagesTemplate
displayName: 'Build with Nested Stages Template'
jobs:
- template: 'template-jobs-nested-build.yaml'
parameters:
vmImage: '${{ parameters.vmImage }}'
message: '${{ parameters.message }}'
# template-stages-nested-release.yaml
parameters:
templateLevel: ''
vmImage: ''
message: ''
stages:
- stage: ReleaseWithNestedStagesTemplate
displayName: 'Release with Nested Stages Template'
jobs:
- template: 'template-jobs-nested-release.yaml'
parameters:
templateLevel: '${{ parameters.templateLevel }}'
vmImage: '${{ parameters.vmImage }}'
message: '${{ parameters.message }}'
# template-steps-build.yaml
parameters:
message: ''
steps:
- task: PowerShell@2
displayName: 'Echo Greeting in PowerShell'
inputs:
targetType: Inline
script: |
Write-Host "$(Greeting)"
Write-Host "${{ parameters.message }}"
# template-steps-release.yaml
parameters:
message: ''
steps:
- task: PowerShell@2
displayName: 'Echo Greeting in PowerShell'
inputs:
targetType: Inline
script: |
Write-Host "$(Greeting)"
Write-Host "${{ parameters.message }}"
# tmplate-stages-release.yaml
parameters:
templateLevel: ''
vmImage: ''
message: ''
stages:
- stage: ReleaseWithStagesTemplate
displayName: 'Release with Stages Template'
jobs:
- deployment: TemplatedStage
displayName: 'Templated Stage'
pool:
vmImage: '${{ parameters.vmImage }}'
environment: release-with-${{ parameters.templateLevel }}-template
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
displayName: 'Echo Greeting in PowerShell'
inputs:
targetType: Inline
script: |
Write-Host "$(Greeting)"
Write-Host "${{ parameters.message }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.