Azure devops 如何在Ubuntu上的Azure管道中访问同一项目的私有存储库?

Azure devops 如何在Ubuntu上的Azure管道中访问同一项目的私有存储库?,azure-devops,azure-pipelines,Azure Devops,Azure Pipelines,用例是,我们有一个node.js项目,它的一个依赖项指向同一项目中的另一个私有存储库,如下所示: package.json { ... "dependencies": { ... "my-package": "git+https://myorganization.visualstudio.com/DefaultCollection/myproject/_git/myotherrepo#mybranch" }

用例是,我们有一个node.js项目,它的一个依赖项指向同一项目中的另一个私有存储库,如下所示:

package.json

{
  ...
  "dependencies": {
    ...
    "my-package": "git+https://myorganization.visualstudio.com/DefaultCollection/myproject/_git/myotherrepo#mybranch"
  }
}
否运行
npm安装的步骤由于身份验证失败而失败


运行管道的ubuntu VM似乎没有访问任何存储库的权限。

您需要提供私有repo的凭据,即使它们在同一个项目中。请参见以下示例:

您可以在私有回购url中显式输入。不建议使用这种方式,因为它将在package.json中公开您的PAT

"dependencies": {
    ...
    "my-package": "git+https://PersonalAccessToken@myorganization.visualstudio.com/DefaultCollection/myproject/_git/myotherrepo#mybranch"
  }
更安全的方法是在管道执行期间添加PersonalAccessToken。请参见以下示例:

1、定义您的package.json,如下所示,使用令牌(即,
{token}
)替换PAT

"my-package": "git+https://#{Token}#@myorganization.visualstudio.com/DefaultCollection/myproject/_git/myotherrepo#mybranch"
2、在npm安装任务之前添加一个任务,用预定义的。例如,任务:。如下所示配置任务

- task: kasunkodagoda.regex-match-replace.regex-match-replace.RegExMatchReplace@2
  displayName: 'RegEx Match & Replace'
  inputs:
    PathToFile: package.json
    RegEx: '#{.*}#'   ##match #{Token}# in the package.json 
    ValueToReplace: '$(System.accesstoken)'
3,如果您使用的是经典管道。您需要启用
允许脚本访问OAuth令牌
,以便在步骤2中获得预定义system.accessstoken的值。请参见下面的屏幕截图


你在哪里托管这个私有回购?就像我在同一个Azure项目中说的。关于多重回购,我发现Azure有一个内置的令牌替换任务,它与你的任务基本相同。