You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps:经典转YAML管道npm安装私有库遇TF401019错误

Azure经典构建管道转YAML管道的权限问题排查与解决

我正在将Azure经典构建管道转换为YAML管道,定义的步骤如下:

parameters:
  RestoreBuildProjects: '**/*.csproj'
  buildConfiguration: 'Any CPU'
  TestProjects: '**/*Tests/*.csproj'

stages:

- stage: Build
  condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
  
  jobs:
  - job: Build_Application
    continueOnError: false
    pool:
      vmImage: 'ubuntu-latest'

    steps:
    - checkout: self
      persistCredentials: true
    
    - script: |
        npm install --no-fund -g git+https://builduser:$(System.AccessToken)@ourrepos.visualstudio.com/Projects/_git/Util
      displayName: 'npm install util'
      workingDirectory: $(Build.SourcesDirectory)

执行时出现如下错误:

npm ERR! command git --no-replace-objects ls-remote https://builduser:***@ourrepos.visualstudio.com/Projects/_git/Util
npm ERR! remote: TF401019: The Git repository with name or identifier Util does not exist or you do not have permissions for the operation you are attempting.
npm ERR! fatal: repository 'https://ourrepos.visualstudio.com/Projects/_git/Util/' not found

我已尝试以下操作:

  • 添加/移除checkout步骤
  • 使用/不使用sudo npm
  • 将builduser替换为user
  • 从父YAML文件传入System.AccessToken作为参数
  • 确保Limit job authorization scope to current project for non-release pipelines为OFF
  • 确保Limit job authorization scope to current project for release pipelines为OFF
  • 确保Protect access to repositories in YAML pipelines为OFF

以及上述操作的组合。该脚本步骤在经典管道中可正常运行,但在YAML管道中失败,我怀疑遗漏了YAML特有的脚本运行或环境变量访问细节。还有其他需要尝试的操作吗?

编辑: 我已解决问题,但未修复根本原因。奇怪的是,仅通过重新创建包含完全相同代码的管道文件,该命令现在可正常运行。我暂不清楚原因,后续会详细排查,目前问题已解决。感谢所有提供帮助的人。

内容的提问来源于stack exchange,提问作者Matt W

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 03:22:32