簡體   English   中英

Azure DevOps Pipelines 在使用 ReadyToRun 時失敗

[英]Azure DevOps Pipelines fails when using ReadyToRun

我們目前正在嘗試在 DevOps 中以發布模式發布 .NET 項目,並啟用ReadyToRun ,該項目引用位於另一個項目(我們的共享庫)中的一些工件。

問題是每次我們運行dotnet publish命令時,它都會拋出一大堆 401 授權錯誤,如下所示:

在此處輸入圖像描述

真正重要的是,當發布為Debug或沒有ReadyToRun時,這個問題不會發生

微軟無法幫助我們,並一直指出,肯定存在授權問題,因為它給了我們一個 401。但這並沒有真正的意義,因為它在沒有 ReadyToRun 的情況下顯然可以正常工作,這意味着它可以成功檢索工件。

這是我們目前使用的管道:

# 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:
- main

pool:
  vmImage: 'windows-2022'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  publish.buildConfiguration: 'Publish'
  publish.path: '$(System.DefaultWorkingDirectory)\publish\'
  publish.artifactFolderName : 'Packages'
  
  #App API
  projectName.appApi: 'Linak.Deskline.Tracking.AppApi'
  projectPath.appApi: '.\Sources\Linak.Deskline.Tracking\Linak.Deskline.Tracking.AppApi\$(projectName.appApi).csproj'
  ressource.dev.function.appApi: 'func-dtr-app-weu-dev-01'
  ressource.tst.function.appApi: 'func-dtr-app-weu-tst-01'
  ressource.prod.function.appApi: 'func-dtr-app-weu-prod-01'

  #Integrator API
  projectName.integratorApi: 'Linak.Deskline.Tracking.integratorApi'
  projectPath.integratorApi: '.\Sources\Linak.Deskline.Tracking\Linak.Deskline.Tracking.IntegratorApi\$(projectName.integratorApi).csproj'
  ressource.dev.function.integratorApi: 'func-dtr-integrator-weu-dev-01'
  ressource.tst.function.integratorApi: 'func-dtr-integrator-weu-tst-01'
  ressource.prod.function.integratorApi: 'func-dtr-integrator-weu-prod-01'

  #LipDataHandler Api
  projectName.lipDataHandler: 'Linak.Deskline.Tracking.LipDataHandler'
  projectPath.lipDataHandler: '.\Sources\Linak.Deskline.Tracking\Linak.Deskline.Tracking.LipDataHandler\$(projectName.lipDataHandler).csproj'  
  ressource.dev.function.lipDataHandler: 'func-dtr-lipevents-weu-dev-01'
  ressource.tst.function.lipDataHandler: 'func-dtr-lipevents-weu-tst-01'
  ressource.prod.function.lipDataHandler: 'func-dtr-lipevents-weu-prod-01'

stages: 
- stage: Build
  jobs: 
  - job: BuildAndPublishZips
    displayName: Build and publish zip files
    steps:
    
    - task: NuGetToolInstaller@1
      displayName: 'Get Nuget'

    - task: NuGetCommand@2
      displayName: 'Nuget Restore'
      inputs:
        command: 'restore'
        restoreSolution: '$(solution)'
        feedsToUse: 'config'
        nugetConfigPath: '.\Sources\Linak.Deskline.Tracking\nuget.config'
        arguments: '--runtime win-x86'

    - task: DotNetCoreCLI@2
      displayName: 'Build and publish - $(projectName.appApi)'
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '$(projectPath.appApi)'
        arguments: '-o $(publish.path) /bl -c $(publish.buildConfiguration)'

    - task: DotNetCoreCLI@2
      displayName: 'Build and publish - $(projectName.integratorApi) '
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '$(projectPath.integratorApi)'
        arguments: '-o $(publish.path) /bl -c $(publish.buildConfiguration)'
      
    - task: DotNetCoreCLI@2
      displayName: 'Build and publish - $(projectName.lipDataHandler)'
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '$(projectPath.lipDataHandler)'
        arguments: '-o $(publish.path) /bl -c $(publish.buildConfiguration)'
      
    - task: DotNetCoreCLI@2
      displayName: 'Run tests'
      inputs:
        command: 'test'
        projects: '**\*.csproj'
        testRunTitle: 'Deskline Cloud Test'

    - task: PublishPipelineArtifact@1
      displayName: 'Publishing deploy packages'
      inputs:
        targetPath: '$(publish.path)'
        artifact: '$(publish.artifactFolderName)'
        publishLocation: 'pipeline'

#DEV
- stage: Deploy_DEV
  dependsOn: Build
  jobs: 
  - deployment: Deploy_DEV
    displayName: 'Deploy to DEV'
    environment: 'Tracking - DEV'
    strategy:
      runOnce:
        deploy:
          steps: 
          - task: PowerShell@2  
            displayName: "List build artifacts"
            inputs:
              targetType: 'inline'
              script: |
                # Write your PowerShell commands here.
                Write-Host "cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)"
                cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)
                dir   
          - task: AzureFunctionApp@1
            displayName: 'Deploy DEV - $(projectName.integratorApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Development'
              appType: 'functionApp'
              appName: $(ressource.dev.function.integratorApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.integratorApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy DEV - $(projectName.appApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Development'
              appType: 'functionApp'
              appName: $(ressource.dev.function.appApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.appApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy DEV - $(projectName.lipDataHandler)'
            inputs:
              azureSubscription: 'Deskline Cloud - Development'
              appType: 'functionApp'
              appName: $(ressource.dev.function.lipDataHandler)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.lipDataHandler).zip'
              deploymentMethod: 'zipDeploy'
#TEST
- stage: Deploy_TEST
  dependsOn: 'Deploy_DEV'
  jobs: 
  - deployment: Deploy_TEST
    displayName: Deploy to TEST
    environment: 'Tracking - TEST'
    strategy:
      runOnce:
        deploy:
          steps: 
          - task: PowerShell@2  
            displayName: "List build artifacts"
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)"
                cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)
                dir   
          - task: AzureFunctionApp@1
            displayName: 'Deploy TEST - $(projectName.integratorApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Test'
              appType: 'functionApp'
              appName: $(ressource.tst.function.integratorApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.integratorApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy TEST - $(projectName.appApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Test'
              appType: 'functionApp'
              appName: $(ressource.tst.function.appApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.appApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy DEV - $(projectName.lipDataHandler)'
            inputs:
              azureSubscription: 'Deskline Cloud - Test'
              appType: 'functionApp'
              appName: $(ressource.tst.function.lipDataHandler)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.lipDataHandler).zip'
              deploymentMethod: 'zipDeploy'
#PROD
- stage: Deploy_PROD
  dependsOn: 'Deploy_TEST'
  jobs: 
  - deployment: Deploy_PROD
    displayName: Deploy to PROD
    environment: 'Tracking - PROD'
    strategy:
      runOnce:
        deploy:
          steps: 
          - task: PowerShell@2  
            displayName: "List build artifacts"
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)"
                cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)
                dir   
          - task: AzureFunctionApp@1
            displayName: 'Deploy PROD - $(projectName.integratorApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Production'
              appType: 'functionApp'
              appName: $(ressource.prod.function.integratorApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.integratorApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy PROD - $(projectName.appApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Production'
              appType: 'functionApp'
              appName: $(ressource.prod.function.appApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.appApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy PROD - $(projectName.lipDataHandler)'
            inputs:
              azureSubscription: 'Deskline Cloud - Production'
              appType: 'functionApp'
              appName: $(ressource.prod.function.lipDataHandler)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.lipDataHandler).zip'
              deploymentMethod: 'zipDeploy'

它在以下步驟中失敗:

- task: DotNetCoreCLI@2
  displayName: 'Build and publish - $(projectName.appApi)'
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '$(projectPath.appApi)'
    arguments: '-o $(publish.path) /bl -c $(publish.buildConfiguration)'

我們已經嘗試了不同的方法,例如:

  1. 將 -no-restore 添加到發布命令

  2. 將此部分添加到管道中:

    腳步:

    • 任務:UseDotNet@2 displayName:'使用 .NET Core sdk 6.0.x' 輸入:版本:6.0.x
  3. 確保授權失敗的構建服務可以訪問共享庫中的工件

在此處輸入圖像描述

微軟現在已經有 10 人參與此案,我不覺得我們無處可去。 所以我想,也許這里有人有更好的解決方案?

您是否嘗試在“發布”之前構建您的項目?

- task: DotNetCoreCLI@2
  displayName: dotnet build
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration ${{ BuildConfiguration }}'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM