I am doing some investigation into how we an ensure that our YAML pipelines are using the same steps to do e.g. verification of unit tests. I have set up a couple of Environments and I thought that I could use the "Approval and checks" functionality with regards to "Required template".
I actually thought that it would be super simple - but I cannot get the parser/runner engine to accept my "extends" configuration.
My YAML-pipeline is this:
stages:
- stage: Build
jobs:
- job: BuildJob
steps:
- script: echo Building!
- stage: Test
jobs:
- job: TestOnWindows
steps:
- script: echo Testing on Windows!
- job: TestOnLinux
steps:
- script: echo Testing on Linux!
- deployment: DeployToTest
environment: 'Test'
- stage: Deploy
jobs:
- job: Deploy
steps:
- script: echo Deploying the code!
- deployment: DeployToProd
environment: 'Prod'
It really does nothing - except for handling a few stages with approval on usage of the associated environments.
I thought that I could simply add the extends
property at the top - like this:
extends:
template: resource-template.yml
stages:
- stage: Build
jobs:
- job: BuildJob
steps:
- script: echo Building!
- stage: Test
jobs:
- job: TestOnWindows
steps:
- script: echo Testing on Windows!
- job: TestOnLinux
steps:
- script: echo Testing on Linux!
- deployment: DeployToTest
environment: 'Test'
- stage: Deploy
jobs:
- job: Deploy
steps:
- script: echo Deploying the code!
- deployment: DeployToProd
environment: 'Prod'
My resource-template.yml
-file is this
# File: resource-template.yml
# steps:
#- script: echo Echoing from template!
In other words - it is completely empty.
Note: can this by the cause of the error? That I cannot extend from an empty template? The documentation is a bit vague on the requirements of the extended pipeline. I have also tried to add a trigger declaration to the extended template - with same result.
The editor alerts me with orange squiggles that "unexpected property extends" and if I ignore it and try to run my pipeline, I get the error "/azure-pipelines.yml (Line: 4, Col: 1): Unexpected value 'stages'"
What am I doing wrong? I have examined the Azure Pipelines YAML schema and cannot find any indication that I should not be able to do what I do.
The reference point of my investigation was this page: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#extend-from-a-template
I can re-use my template by writing one of my stage-declarations like this:
- stage: Test
jobs:
- job: TestOnWindows
steps:
- template: resource-template.yml
- script: echo Testing on Windows!
- job: TestOnLinux
steps:
- script: echo Testing on Linux!
- deployment: DeployToTest
environment: 'Test'
But that "inclusion" of the template does not trigger the approval/check condition on the environment
Thank you :-)
/Jesper
Look like there is no way to override stages by extending from other yaml. Maybe thinking of different approach.. Using stage template?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With