Packages failed to publish due to TypeError: Cannot read property 'toLowerCase' of null

Packages failed to publish due to TypeError: Cannot read property 'toLowerCase' of null

在我的 azure devops 管道中。首先构建 conda 包并通过 UniversalPackages@0 任务发布。

构建和上传代码片段如下所示

- stage: build_upload_package 
  displayName: Build and upload package
  pool:
    name: Private Agent Eve 
  jobs:
  - job: build_upload_package
    displayName: Build and Upload Package
    condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/release'))
    container:
      image: <azureacr_repo.io>/conda:latest   //modified to remove the information
      endpoint: NameOfTheServiceConnection     //modified to remove the information
    steps:

      - bash: |
          echo "##vso[task.prependpath]$CONDA/bin"
          conda build . --output-folder $(Build.ArtifactStagingDirectory)
        displayName: Build Package
      - bash: echo "##vso[task.setvariable variable=packageName]$(basename $(gitRepoName))"
        displayName: Set Package Name


      - task: UniversalPackages@0  //Error appears here
        displayName: Upload to Azure Universal Packages
        inputs:
          command: publish
          publishDirectory: '$(Build.ArtifactStagingDirectory)'
          vstsFeedPublish: 'project_1/feed_1'   //modified to remove the information
          vstsFeedPackagePublish: '$(packageName)'
          versionOption: patch
          packagePublishDescription: 'upload a Conda Package'

Universal UniversalPackages 任务的错误如下所示

2020-11-24T17:54:48.9628862Z ##[section]Starting: Upload to Azure Universal Packages
2020-11-24T17:54:48.9645737Z ==============================================================================
2020-11-24T17:54:48.9646470Z Task         : Universal packages
2020-11-24T17:54:48.9647068Z Description  : Download or publish Universal Packages
2020-11-24T17:54:48.9647636Z Version      : 0.175.0
2020-11-24T17:54:48.9648154Z Author       : Microsoft Corporation
2020-11-24T17:54:48.9648809Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks
2020-11-24T17:54:48.9649526Z ==============================================================================
2020-11-24T17:54:49.4896147Z SYSTEMVSSCONNECTION exists true
2020-11-24T17:54:50.1267511Z Downloading: https://08wvsblobprodsu6weus73.vsblob.vsassets.io/artifacttool/artifacttool-linux-x64-Release_0.2.172.zip?sv=2019-02-02&sr=b&sig=FvnCFjIg7ZBmIapFcCcWDC1%2F7pajvzvgo0fR2Y3YYeU%3D&spr=https&se=2020-11-24T18%3A54%3A51Z&sp=r&P1=1606243791&P2=11&P3=2&P4=1nPT99OOlNXc9xNzoCS6LpVATo%2bW4fIskTJ8u6olWMk%3d
2020-11-24T17:54:56.4979070Z Caching tool: ArtifactTool 0.2.172 x64
2020-11-24T17:54:56.7183832Z SYSTEMVSSCONNECTION exists true
2020-11-24T17:54:58.7313555Z ##[error]TypeError: Cannot read property 'toLowerCase' of null
2020-11-24T17:54:58.7323845Z ##[error]Packages failed to publish
2020-11-24T17:54:58.7641267Z ##[section]Finishing: Upload to Azure Universal Packages

问题:

我该如何解决这个问题?

我对这个任务做了一些测试:UniversalPackages@0。我注意到任务中有以下提示:

Universal package names must be one or more lowercase alphanumeric segments separated by a dash, dot or underscore. The package name must be under 256 characters.

当您的 packageName 包含大写字母或其他特殊字符时,此任务将失败。

您可以尝试以下脚本:

        - task: PowerShell@2
          inputs:
           targetType: 'inline'
           script: |
              $name = $(basename $(gitRepoName)).ToLower()
              Write-Host "##vso[task.setvariable variable=packageName]$name"

        - task: UniversalPackages@0
          inputs:
            command: 'publish'
            publishDirectory: '$(Build.ArtifactStagingDirectory)'          
            vstsFeedPublish: 'project_1/feed_1'
            vstsFeedPackagePublish: '$(packageName)'
            versionOption: 'patch'

Powershell 任务可以将 RepoName 小写。

我想我发现了错误,gitRepoName 是一个模板参数,它应该被访问为 ${{ gitRepoName }} 而不是 $(gitRepoName)