【问题标题】:Can someone please tell me why Azure Pipelines does not like this yaml file?有人可以告诉我为什么 Azure Pipelines 不喜欢这个 yaml 文件吗?
【发布时间】:2021-03-26 17:21:01
【问题描述】:
--- 
variables: 
     azureSubscription: 'Visual Studio Professional Subscription (237bc9da-22ad-49ea-8411-6cf6a190c18f)'
     RG: ClassroomInTheCloud
jobs:
- job: 1   
  steps:

    - task: AzureCLI@1
      dislayName: 'Azure CLI '
      inputs:
       azureSubscription: $(azureSubscription)
       scriptLocation: inlineScript
       inlineScript: |
        mkdir $(Pipeline.Workspace)\BlobFile
        az storage blob download --container-name $(containername) --file '$(Pipeline.Workspace)/s/student.json' --name 'student.json' --connection-string 'VALUE IN HERE'


    - pwsh: |
       cd '/home/vsts/work/1/s/'
       ls
       $armOutput = Get-Content '/home/vsts/work/1/s/student.json' | convertfrom-json
       $studentvalue = $armOutput.studentvalue 
       $type = $armOutput.type
       Write-Host "The value of [$studentvalue] is [$type]"
       Write-Output "##vso[task.setvariable variable=$studentvalue;]$type"
       Write-Output "##vso[task.setvariable variable=$studentvalue;isOutput=true]$studentvalue"
       Write-Output "The Value of studentvalue is [$studentvalue]"
      name: setvarStep

    - script: | 
        echo $(studentvalue)

- job: 2
  displayName: Create Web App 
  dependsOn: 1
  variables:
   webappname: $[studentvalue]

   steps: 
     - task: AzureWebApp@1
       inputs:
       azureSubscription: $(azureSubscription)
       resourceGroupName: $(RG)
       appName: $(webappname)
       package: $(System.DefaultWorkingDirectory)**/*.csproj

     - task: AzureAppServiceSettings@1
       displayName: Azure App Service Settings
       inputs:
       azureSubscription: $(azureSubscription)
       appName: $(webappname)
   # To deploy the settings on a slot, provide slot name as below. By default, the settings would be applied to the actual Web App (Production slot)
   # slotName: staging
       appSettings: |
        [
           {
              "name": "DIAGNOSTICS_AZUREBLOBCONTAINERSASURL",
              "value": "VALUEINHERE",
              "slotSetting": false
           },
           {
              "name": "DIAGNOSTICS_AZUREBLOBRETENTIONINDAYS",
              "value": "365",
              "slotSetting": false
           },
           {
              "name": "OEM",
              "value": "netsupport",
              "slotSetting": false
           },
           {
              "name": "SCM_REPOSITORY_PATH",
              "value": "d:\\home\\respository",
              "slotSetting": false
           },
           {
              "name": "VIDEO_CLIENT_URL",
              "value": "https://signal-uks.classroom.cloud",
              "slotSetting": false
           },
           {
              "name": "WEBSITE_NODE_DEFAULT_VERSION",
              "value": "10.15.2",
              "slotSetting": false
           }
        ]

谁能告诉我为什么在将此 YAML 文件放入管道时出现以下错误?

Line 14, Col 7: Unexpected Value Display Name
Line 45, Col 6: A sequence was not expected

【问题讨论】:

  • 我可能会从修改你的缩进开始。然后,由于您显示的是 YAML 的 sn-p,因此我会突出显示它抱怨的特定行,因为您的示例中没有行号。

标签: azure azure-devops


【解决方案1】:

请先查看此文档:YAML schema referenceDefine variables,以下是设置多作业输出变量的示例 yaml。

jobs:
# Set an output variable from job A
- job: A
  pool:
    vmImage: 'vs2017-win2016'
  steps:
  - powershell: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value"
    name: setvarStep
  - script: echo $(setvarStep.myOutputVar)
    name: echovar

# Map the variable into job B
- job: B
  dependsOn: A
  pool:
    vmImage: 'ubuntu-18.04'
  variables:
    myVarFromJobA: $[ dependencies.A.outputs['setvarStep.myOutputVar'] ]  # map in the variable
                                                                          # remember, expressions require single quotes
  steps:
  - script: echo $(myVarFromJobA)
    name: echovar

因此以下 yaml 的 sn-p 应该是正确的语法供您参考。

pool:
  vmImage: windows-latest

variables: 
  azureSubscription: 'subscription here'
  RG: 'WClassroomInTheCloud'

jobs:
- job: job1   
  steps:
  - task: AzureCLI@1
    displayName: 'Azure CLI '
    inputs:
      azureSubscription: $(azureSubscription)
      scriptLocation: inlineScript
      inlineScript: |
        mkdir $(Pipeline.Workspace)\BlobFile
        az storage blob download --container-name $(containername) --file '$(Pipeline.Workspace)/s/student.json' --name 'student.json' --connection-string 'VALUE IN HERE'

  - pwsh: |
      cd '/home/vsts/work/1/s/'
      ls
      $armOutput = Get-Content '/home/vsts/work/1/s/student.json' | convertfrom-json
      $student = $armOutput.studentvalue #use student not studentvalue
      $type = $armOutput.type
      Write-Host "The value of [$student] is [$type]"
      Write-Host "##vso[task.setvariable variable=studentvalue;isOutput=true]$student" #use studentvalue not $studentvalue
    name: setvarStep

  - script: echo $(setvarStep.studentvalue)
    name: echovar

- job: job2
  displayName: Create Web App 
  dependsOn: job1
  variables:
    webappname: $[ dependencies.job1.outputs['setvarStep.studentvalue'] ]

  steps: 
  
  - task: AzureWebApp@1
    inputs:
      azureSubscription: $(azureSubscription)
      appType: 'webApp'
      resourceGroupName: $(RG)
      appName: $(webappname)
      package: $(System.DefaultWorkingDirectory)**/*.csproj

  - task: AzureAppServiceSettings@1
    inputs:
      azureSubscription: $(azureSubscription)
      appName: $(webappname)
      resourceGroupName: $(RG)
      # To deploy the settings on a slot, provide slot name as below. By default, the settings would be applied to the actual Web App (Production slot)
      # slotName: staging
      appSettings: |
        {
          "name": "DIAGNOSTICS_AZUREBLOBCONTAINERSASURL",
          "value": "VALUEINHERE",
          "slotSetting": false
        },
        {
          "name": "DIAGNOSTICS_AZUREBLOBRETENTIONINDAYS",
          "value": "365",
          "slotSetting": false
        },
        {
          "name": "OEM",
          "value": "netsupport",
          "slotSetting": false
        },
        {
          "name": "SCM_REPOSITORY_PATH",
          "value": "d:\\home\\respository",
          "slotSetting": false
        },
        {
          "name": "VIDEO_CLIENT_URL",
          "value": "https://signal-uks.classroom.cloud",
          "slotSetting": false
        },
        {
          "name": "WEBSITE_NODE_DEFAULT_VERSION",
          "value": "10.15.2",
          "slotSetting": false
        }

【讨论】:

  • 谢谢你,我现在可以看到哪里出错了,我只是无法理解传递变量定义,这对我来说很有意义。我确实阅读了这两篇文章以及更多内容,但现在我看到了你的文章,一个伟大的时刻发生了,所以谢谢你。
【解决方案2】:

第二个错误是因为第 40 行的 steps 处于 webappname 的级别,而它本应处于 variables 的级别。通常不应使用单空格缩进来避免此类错误。

我不确定第一个错误,但请尝试在第 10 行写 displayName 而不是 dislayName

【讨论】:

    猜你喜欢
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 2021-11-16
    相关资源
    最近更新 更多