【问题标题】:Using stages in Azure DevOps Pipeline : Unexpected value 'stages'在 Azure DevOps Pipeline 中使用阶段:意外值“阶段”
【发布时间】:2019-09-01 12:28:32
【问题描述】:

我创建了一个 Azure-Pipelines 文件,其开头如下:

pool:
  vmImage: 'Ubuntu-16.04'

trigger:
- master

variables:
  buildConfiguration: 'Release'
  buildPlatform: 'any cpu'
  version: '0.2.0'
  azureSubscription: 'Azure.Nupaya'
  azureAppType: 'Web App on Windows'
  webAppName: 'api'

stages:

- stage: 'Prepare'
  displayName: 'Prepare'

  jobs:

  - job: 'Setup'
    steps:
    - task: DotNetCoreInstaller@0
      displayName: 'Install'
      inputs:
        packageType: 'sdk'
        version: '2.2.105'

当我运行它时,我得到了错误:

 Unexpected value 'stages'

Yaml 文件不支持阶段吗?

我在 Microsoft Docs 中检查了Schema ...

我错过了什么?

【问题讨论】:

  • 很奇怪,无论如何,它们就像一个月前一样被称为阶段。您介意删除不必要的换行符,看看是否有帮助?
  • @4c74356b41 阶段变成了工作。米格尔为什么需要舞台?工作不适合你?
  • @ShaykiAbramczyk 我的想法是在 Git 存储库中由 Master 分支触发恢复、构建、测试、发布的第一阶段。还有一秒钟部署到 Azure,但手动触发。这有意义吗?这可能吗?这可以通过作业完成吗?
  • @MiguelMoura 部署到 azure 应该是您的“发布”,而不是在 Build 中。
  • @ShaykiAbramczyk 是的,但我可以使用 YML 文件来实现吗?所以我可以在我的 Git 存储库中使用它而不是使用 de Azure DevOps UI?这就是我想要做的。

标签: asp.net-core azure-devops azure-pipelines


【解决方案1】:

在使用 Azure DevOps 进行了一些尝试和测试之后,您似乎在 job 属性下定义了 pool,以便我们为不同的作业定义不同的代理池.

因此,对于您的示例,它将是:

trigger:
- master

variables:
  buildConfiguration: 'Release'
  buildPlatform: 'any cpu'
  version: '0.2.0'
  azureSubscription: 'Azure.Nupaya'
  azureAppType: 'Web App on Windows'
  webAppName: 'api'

stages:

- stage: 'Prepare'
  displayName: 'Prepare'

  jobs:

  - job: 'Setup'
    pool:
      vmImage: 'Ubuntu-16.04'
    steps:
    - task: DotNetCoreInstaller@0
      displayName: 'Install'
      inputs:
        packageType: 'sdk'
        version: '2.2.105'

【讨论】:

  • 我得到了意想不到的价值“工作”。遵循您的结构,现在错误消失了。谢谢
【解决方案2】:

我的问题是我使用的密钥 services: 必须嵌套在作业下。

违规代码直接来自这些azure docs。它们显示 services: 直接在 yaml 文档的根目录中使用。但是,这仅在文档中有效,因为在未指定作业或阶段时,隐含范围为 job,如他们的示例所示。将 services: 移到需要它的作业下可以解决问题。

来自 Azure Docs 的示例:

resources:
  containers:
  - container: my_container
    image: buildpack-deps:focal
  - container: nginx
    image: nginx


pool:
  vmImage: 'ubuntu-20.04'

container: my_container
services:
  nginx: nginx

steps:
- script: |
    curl nginx
  displayName: Show that nginx is running

请注意,他们在根目录中使用steps: 而不是stages:。这导致了我的问题。

如果您遇到此问题,或与jobs: 相关的问题,请一次注释掉一个键,尤其是新添加的键,以找出导致错误的根键。找到它后,请检查 YAML Schema definition 以查看该密钥是否在隐含的范围内被允许。如果 steps:、jobs: 或 stages: 用作根键,请特别注意隐含范围。

【讨论】:

    【解决方案3】:

    如果您发现自己拥有意想不到的价值“工作”,请尝试暴风雨结构https://stackoverflow.com/a/56111720/1977871

    我的,正在工作的在这里。

    # ASP.NET
    # Build and test ASP.NET projects.
    # Add steps that publish symbols, save build artifacts, deploy, and more:
    # https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
    
    trigger:
    - master
    
    variables:
      solution: '**/*.sln'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'
      finalBuildArtifactName: 'aspnetFrameworkDropFromYaml'
    
    stages:
    - stage: 'Prepare'
      displayName: 'Prepare'
    
      jobs:
      - job: 'BuildPipelineNetFrameworkYaml'
        displayName: 'Build pipeline NetFramework Yaml'
        pool:
          vmImage: 'windows-latest'
          name: VivekPool1
        steps:
        - task: NuGetToolInstaller@1
          displayName: 'Use NuGet 5 3 1'
          inputs:
            versionSpec: 5.3.1
    
        - script: |
            echo $(build.artifactstagingdirectory) $(build.buildnumber)
            echo $(RestoreBuildProjects)   
            echo $(BuildConfiguration)
            echo The current branch is - $(Build.SourceBranchName)!!!!.
            echo $(finalBuildArtifactName)
          displayName: 'Command Line Script to write out some vars'
    
        - powershell: |
            # Write your PowerShell commands here.
            Write-Host "The following are the environment vars."
            get-childitem -path env:*
          displayName: 'PowerShell script to write out env vars'
        - task: NuGetCommand@2
          displayName: 'NuGet restore'
          inputs:
            restoreSolution: '$(solution)'
    
        - task: VSBuild@1
          displayName: 'Build solution'
          inputs:
            solution: '$(solution)'
            msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
            platform: '$(buildPlatform)'
            configuration: '$(buildConfiguration)'
    
        - task: VSTest@2
          displayName: 'Test Assemblies'
          inputs:
            testAssemblyVer2: |
              **\$(BuildConfiguration)\*test*.dll
              !**\obj\**
              !**\$(BuildConfiguration)\*SeleniumTest*.dll
            platform: '$(buildPlatform)'
            configuration: '$(buildConfiguration)'
    
        - task: PublishSymbols@2
          displayName: 'Publish symbols path'
          inputs:
            SearchPattern: '**\bin\**\*.pdb'
            PublishSymbols: false
          continueOnError: true
    
        - task: CopyFiles@2
          displayName: 'Copy ProvisionNetFramework Files to drop directory'
          inputs:
            SourceFolder: Cicd/provisionForNetFramework
            TargetFolder: '$(build.artifactstagingdirectory)/provisionForNetFramework'
    
        - task: PublishBuildArtifacts@1
          displayName: 'Publish Artifact'
          inputs:
            PathtoPublish: '$(build.artifactstagingdirectory)'
            ArtifactName: '$(finalBuildArtifactName)'
          condition: succeededOrFailed()
    

    【讨论】:

      【解决方案4】:

      只是在这里插话。

      我在这个脚本中有一条黄色波浪线“意外的价值工作”:

      trigger:
       branches:
         include:
         - master
       batch: true
      
      jobs:
        -job: Build
          pool:
           name: MyAgent
           demands: 
            - MSBuild
            - SqlPackage  
      

      你能看出问题吗?

      -job: Build 应该是- job: Build

      人们如何在不爆炸的情况下实际使用它。

      【讨论】:

        【解决方案5】:

        确保您以正确的方式使用命令,并且您不会意外地将step 与stages 处于同一级别。 如果您将 JSON 从简单的基于步骤的结构重构为“基于阶段”的结构,则可能会发生这种情况。

        在我的情况下,问题是在舞台内的script 声明前面缺少step,并且丢失了step-与stages 处于同一级别的声明。

        【讨论】:

          猜你喜欢
          • 2020-07-04
          • 1970-01-01
          • 1970-01-01
          • 2021-09-08
          • 2022-09-23
          • 2021-10-14
          • 2021-03-25
          • 2020-12-02
          • 2021-03-18
          相关资源
          最近更新 更多