简体   繁体   English

如何解决 Azure devops 管道 yml 中的“意外值‘阶段’天蓝色管道”

[英]How to resolve "unexpected value 'stages' azure pipelines" in Azure devops pipeline yml

I am new to Azure devops.我是 Azure DevOps 的新手。 as part of poc, i am trying to build a java based docker image.作为 poc 的一部分,我正在尝试构建一个基于 Java 的 docker 镜像。

so i have following pipeline yaml file所以我有以下管道yaml文件

# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'

resources:
- repo: self

variables:
  tag: '$(Build.BuildId)'

stages:
- stage: Build
  displayName: Build image
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: Docker@2
      displayName: Build an image
      inputs:
        command: build
        dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
        tags: |
          $(tag)

Expected预期的

What i expected, this pipeline need to create a java application (jar file) and then it should create a docker image using this jar我所期望的,这个管道需要创建一个java应用程序(jar文件),然后它应该使用这个jar创建一个docker镜像

Actual:实际的:

i am getting below error我得到以下错误

unexpected value 'stages' azure pipelines

I didnt understand the issue...没看懂问题。。。

Appreciated if anybody can help on this..?如果有人可以帮助解决这个问题,不胜感激..?

Thanks谢谢

Please move this into job before your first task - task: Docker@2请在您的第一个任务之前将其转移到工作中- task: Docker@2

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'

This is simply syntax issue.这只是语法问题。 If you use steps you cant use stages on the root level.如果您使用步骤,则不能在根级别使用阶段。 Here you may check syntax. 在这里你可以检查语法。

If you want to have jar creation as separate stage/job you have to define explicitly this as another stage or job.如果要将 jar 创建作为单独的阶段/作业,则必须将其明确定义为另一个阶段或作业。 However in that way you need to publish and then download your jar as pipeline artifact .但是,通过这种方式,您需要发布并下载您的 jar 作为管道工件

If you stay with one single job you may just use:如果你只做一份工作,你可以使用:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  tag: '$(Build.BuildId)'

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'
- task: Docker@2
  displayName: Build an image
  inputs:
    command: build
    dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
    tags: |
      $(tag)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM