我在使用 Azure DevOps、工件和 YAML 时做错了吗?

Am I doing this wrong with Azure DevOps, an Artifact and YAML?

我正在尝试从一个工件构建一个网络应用程序,并从一个 JSON 文件中为应用程序传递一个变量值,所有这些都在 YAML 中。

我遇到的问题是在管道的末端。我可以在没有 APP 名称的变量值的情况下构建 Web 应用程序并且它会构建,但是当我尝试将变量作为应用程序名称时它失败并说它看不到工件文件。

我的 YAML 文件代码如下。非常感谢任何指导或帮助。

#pool:
 # vmImage: windows-latest
resources: 
  repositories: 
  - repository: Student
    name: PROJECT NAME/Student
    path:
    - include: /Student/Student 
    type: git 
    ref: master #branch name

variables: 
  System.Debug: true
  azureSubscription: 'MY VALUE HERE'
  RG: 'PROJECTNAME'
  containername: 'private'
  
jobs:
- job: job1
  displayName: Create And Publish Artifact
  pool:
    vmImage: vs2017-win2016
  steps:
  - checkout: Student
    clean: true

  - task: DotNetCoreCLI@2
    displayName: dotnet restore
    inputs:
      command: restore
      projects: '**/*.csproj'

  - task: DotNetCoreCLI@2
    displayName: dotnet build
    inputs:
      projects: '**/*.csproj'
      workingDirectory: Student

  - task: DotNetCoreCLI@2
    displayName: dotnet publish
    inputs:
      command: publish
      projects: '**/*.csproj'
      arguments: --output "$(Build.ArtifactStagingDirectory)"
      zipAfterPublish: true
      modifyOutputPath: false
      workingDirectory: Student

  - task: PublishPipelineArtifact@1
    displayName: Publish Pipeline Artifact
    inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)'
      artifact: 'Student'
      publishLocation: 'pipeline'

- job: job2
  displayName: 'Get Variable Value for Student Env'
  dependsOn: 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 'DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=devscriptstorage;AccountKey'MY VALUE 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: job3
  displayName: Create Web App 
  dependsOn: job2
  variables:
    webappname: $[ dependencies.job2.outputs['setvarStep.studentvalue'] ]

  steps: 

  # creat empty web app with the student value from variable.
  - task: AzureWebApp@1
    inputs:
      azureSubscription: $(azureSubscription)
      appType: 'webApp'
      resourceGroupName: $(RG)
      appName: $(webappname)

  # download the artifact drop from the previous job
  - task: DownloadBuildArtifacts@0
    inputs:
      artifactName: Student

  # deploy to Azure Web App 
  - task: AzureWebApp@1
    inputs:
      azureSubscription: $(azureSubscription)
      appName: $(webappname)

  - 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
        }

我在 Alessandro Mouras 的博客“http://www.alessandromoura.com.br/2020/04/23/azure-devops-publish-and-download-artifacts/”

上找到了这个问题的解决方案

添加以下代码后:

steps: 
  - download: none
  - task: DownloadPipelineArtifact@2
    displayName: 'Download Build Artifacts'
    inputs:
      patterns: '**/*.zip'
      path: '$(Build.ArtifactStagingDirectory)'

它会找到 Artifact 并下载它。我现在遇到的问题是它不会构建 Web 应用程序,因为我有一个变量运行时名称传递给它并且它似乎假设该资源应该已经存在。

这是当前错误:资源 'nsclassroomstudent-dgyn27h2dfoyo' 不存在。部署前资源应该存在。

如果您对 Artifacts、WebApps 和 Azure 有所了解,我会继续努力,我很想在这里听取您的意见。 :)