问题
I have gotten pretty close with my template and my deploy yaml that uses it. However I am getting to errors
Unexpected value 'variables' Unexpected value 'stages'
I am sure I have the syntax wrong, but I can't for the life of me understand why.
Here is the start of my template
#File: template.yml
parameters:
- name: repositoryName
type: string
default: ''
variables:
tag: '$(Build.BuildId)'
buildVmImage: 'ubuntu-latest'
deployPool: 'deploy-pool'
stages:
- stage: Build
jobs:
- job: Build
pool:
vmImage: $(buildVmImage)
steps:
- checkout: self
submodules: recursive
And here is the deploy yaml that uses it
# Repo: Organization/Project
# File: azure-pipelines.yml
trigger:
- develop
- next
- master
resources:
repositories:
- repository: template
type: git
name: AzureDevOps/AzureDevOps
jobs:
- template: template.yml@template
parameters:
repositoryName: 'exampleName'
any help would be appreciated. I am sure it's right in front of my nose but I've been struggling for days so I think it's time to ask for help.
回答1:
Unexpected value 'stages'
Your template.yml
defines a template for stages
, while you're referencing it under jobs
element.
The correct format of multi-stage pipeline is:
stages:
- stage: Build
jobs:
- job: Build
pool:
vmImage: $(buildVmImage)
steps:
- checkout: self
submodules: recursive
- job: Job2
pool:
vmImage: $(buildVmImage)
steps:
...
- stage: Deploy
jobs:
- job: Deploy
pool:
vmImage: $(buildVmImage)
steps:
...
stages=>stage=>jobs=job, so you can't reference stages
template under jobs
element. Changing
jobs:
- template: template.yml@template
To
stages:
- template: template.yml@template
would resolve this issue.
Unexpected value 'variables'
If the variables are for whole pipeline, move it into azure-pipelines.yml
:
trigger:
- master
variables:
tag: '$(Build.BuildId)'
buildVmImage: 'ubuntu-latest'
deployPool: 'deploy-pool'
If the variables are for one specific stage, move it under stage:
stages:
- stage: Build
variables:
variable1: xxx
variable2: xxx
jobs:
- job: Build
pool:
vmImage: $(buildVmImage)
steps:
- checkout: self
submodules: recursive
If the variables are for one job, move them under specific job:
stages:
- stage: Build
jobs:
- job: Build
pool:
vmImage: $(buildVmImage)
variables:
variable1: xxx
variable2: xxx
steps:
- checkout: self
submodules: recursive
The jobs
element doesn't support variables
, job/stage support it instead. Moving the variables to correct scope would resolve this issue.
来源:https://stackoverflow.com/questions/63381680/azure-pipelines-yaml-unexpected-value-variables-and-unexpected-stages