I've been trying to implement as per this blog post
I have created a template yaml that received the environment name as a single parameter.
I'd like to call this from a yaml pipeline using stages. Hoping to reduce code duplication, with the idea being the outer calling pipeline yaml is quite simple. This is what I have for the caller:
trigger: none
stages:
- stage: dev
jobs:
- job: dev
extends:
template: templates\365-response.bicep.template.yml
parameters:
env: dev
- stage: test
jobs:
- job: test
extends:
template: templates\365-response.bicep.template.yml
parameters:
env: test
My template to be called is:
name: Deploy Bicep files $(Build.BuildId)
parameters:
- name: env
type: string
variables:
location: "uksouth"
templateFile: "bicep/365Response.main.json"
pool:
vmImage: "windows-latest"
stages:
- stage: preDeploy
jobs:
- job: listFiles
displayName: List Files
pool:
vmImage: windows-2022
steps:
- powershell: echo $(Build.SourcesDirectory)
- powershell: Get-ChildItem -Path '$(System.DefaultWorkingDirectory)' -recurse
- job: scanWhatif
displayName: scan and run whatif
pool:
vmImage: windows-2022
steps:
- task: AzureCLI@2
displayName: Preview Bicep Changes
inputs:
azureSubscription: "subname-${{parameters.env}}"
scriptType: "bash"
scriptLocation: "inlineScript"
inlineScript: |
az --version
az deployment group what-if --resource-group rg-365Response-${{parameters.kbName}}-001 \
--template-file '$(System.DefaultWorkingDirectory)\bicep\365Response.main.bicep' \
--parameters '$(System.DefaultWorkingDirectory)\bicep\365Response.parameters.${{parameters.kbName}}.json' \
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
environment: ${{ parameters.env }}
strategy:
runOnce:
deploy:
steps:
- task: AzureCLI@2
displayName: Deploy Bicep Changes
inputs:
azureSubscription: "subname-${{parameters.env}}"
scriptType: "bash"
scriptLocation: "inlineScript"
inlineScript: |
az deployment group create --resource-group rg-365Response-${{parameters.env}}-001 \
--template-file '$(System.DefaultWorkingDirectory)\bicep\365Response.main.bicep' \
--parameters '$(System.DefaultWorkingDirectory)\bicep\365Response.parameters.${{parameters.env}}.json'
I seem to have the syntax for calling the template wrong?