在向 Microsoft 提交错误报告之前,我只是想先检查一下这里,看看以前是否有人遇到过这个问题。
我已经按照两个教程使用管理组设置了应用服务连接,其中一个位于 Stack Overflow,另一个位于博客文章中。链接在此:
Azure DevOps Service Connections not showing when setting up a new release pipeline
https://4bes.nl/2019/07/11/step-by-step-manually-create-an-azure-devops-service-connection-to-azure/
根据 Microsoft 文档,当您更改为管理组时,您只需在 YAML 中的应用程序部署任务的 Azure 订阅下的代码中引用该管理组。
引用此处:https://learn.microsoft.com/en-us/azure/devops/pipelines/library/connect-to-azure?view=azure-devops它指出:如果您使用 YAML,请将连接名称作为 azureSubscription 值复制到您的代码中。
然而,当我在 YAML 代码中执行此操作时,我得到:##[error]Error: 'subscriptionId' can not be null.
我的 YAML 代码中有一个 CLI 任务,当我将其升级到版本 2 并引用 PSCORE 的 ScriptType 时,它可以工作并找到 APP Service 连接。然而,当它到达第 119 行或任务标题下:Azure Web App Deploy: $(webappname) 时,它会失败并给我引用的错误。
如果有人以前遇到过这个问题或知道如何解决它,我很乐意听取您的意见。如果不是,则向 Microsoft 提出错误请求。再次....
我在下面包含了我的代码:
#pool:
# vmImage: windows-latest
resources:
repositories:
- repository: Student
name: Classroom In The Cloud/Student
path:
- include: /Student/Student
type: git
ref: master #branch name
variables:
System.Debug: true
azureSubscription: 'CITC-DevPipelines'
RG: 'ClassroomInTheCloud'
Location: West Europe
containername: 'private'
appconnectionname: 'CITC-DevPipelines'
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@2
displayName: 'Azure CLI '
inputs:
azureSubscription: 'CITC-DevPipelines'
scriptType: 'pscore'
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=<MYVALUE>'
- 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
$appservice = $armOutput.appservicevalue
Write-Host "The value of [$student] is [$appservice]"
Write-Host "##vso[task.setvariable variable=studentvalue;isOutput=true]$student" #use studentvalue not $studentvalue
Write-Host "##vso[task.setvariable variable=appservicevalue;isOutput=true]$appservice" #use appservicevalue not $appservice
name: setvarStep
- script: echo $(setvarStep.studentvalue)
- script: echo $(setvarStep.appservicevalue)
name: echovar
- job: job3
displayName: Create Web App
dependsOn: job2
variables:
webappname: $[ dependencies.job2.outputs['setvarStep.studentvalue'] ]
appservicename: $[ dependencies.job2.outputs['setvarStep.appservicevalue'] ]
steps:
# Create Web App
#- task: AzureCLI@1
# displayName: Create Web App $(webappname)
# inputs:
# azureSubscription: '$(azureSubscription)'
# scriptLocation: 'inlineScript'
# inlineScript: 'az webapp create -g $(RG) -p $(azureSubscription) -n $(webappname)'
# Download Artifact File
- download: none
- task: DownloadPipelineArtifact@2
displayName: 'Download Build Artifacts'
inputs:
patterns: '**/*.zip'
path: '$(Build.ArtifactStagingDirectory)'
# deploy to Azure Web App
- task: AzureWebApp@1
displayName: 'Azure Web App Deploy: $(webappname)'
inputs:
package: $(Build.ArtifactStagingDirectory)/**/*.zip
azureSubscription: CITC-DevPipelines
ConnectedServiceName: $(appconnectionname)
appName: '$(webappname)'
ResourceGroupName: $(RG)
# Change App Settings
# - task: AzureCLI@1
# displayName: Change WebApp Settings
# inputs:
# azureSubscription: '$(azureSubscription)'
# scriptLocation: 'inlineScript'
# Arguments input: '$(webappname)'
# inlineScript: |
# 'az webapp config appsettings set --name %1 --resource-group $(RG) --settings '/home/vsts/work/1/s/studentsettings.json' --subscription $(azureSubscription)'
最佳答案
这是管理组服务连接的限制。已经有许多 GitHub 问题跟踪它(即 https://github.com/microsoft/azure-pipelines-tasks/issues/14359 )。
解决方法是使用服务主体连接。
关于azure - 部署 Web 应用程序时,Microsoft Azure 中可能存在错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67121908/