从 Azure 发布管道执行 Git 推送

Nar*_*ril 0 git azure-devops azure-pipelines

我想在来自自托管构建服务器的 Azure Devops 发布管道中从 powershell 脚本执行 git push 。

它在构建管道中工作,但从发布管道中我最终遇到身份验证错误。“允许脚本访问 OAuth 令牌”已激活,并且构建机器具有贡献权限(正如我所说,它在构建管道中工作)。

这是我在 devops protal 中看到的错误:

git : remote: 001f# service=git-receive-pack
At C:\Builds\A1\_work\r1\a\Source\Scripts\CreateTagFromPipeline.ps1:11 char:1
+ git push
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (remote: 001f# service=git-receive-pack:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

PowerShell exited with code '1'.
Run Code Online (Sandbox Code Playgroud)

如果我通过远程桌面登录到机器并手动推送,我会得到一些更好的错误:

$ git push
remote: 001f# service=git-receive-pack
remote: 0000000000aaTF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\58bb64d7-d065-4522-94e2-a153b9fdadd6', scope 'repository'.
remote: TF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\58bb64d7-d065-4522-94e2-a153b9fdadd6', scope 'repository'
fatal: unable to access 'https://our-correct-repo-address-on-dev.azure.com': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)

同样,它适用于构建管道,但不适用于发布管道。

dea*_*rsi 8

-- 开始编辑 -- 您需要为此身份“Build**58bb64d7-d065-4522-94e2-a153b9fdadd6**”授予通用贡献权限。

  1. 在 azure devops 中转到项目设置
  2. 去 repos -> repositories -> 点击你的 repo
  3. 在安全选项卡上, 在“搜索用户和组”中浏览 ID 58bb64d7-d065-4522-94e2-a153b9fdadd6
  4. 单击找到的身份并确保它具有:贡献权限、创建分支、创建标签和读取权限设置为允许

- - 编辑 - -

构建管道是否也在自托管构建服务器上运行?

转到您的构建管道 -> 变量 -> 检查 system.collectionId。

是 58bb64d7-d065-4522-94e2-a153b9fdadd6 吗?

如果这不是您的构建管道中的集合 ID,则意味着您的发布管道中的身份 58bb64d7-d065-4522-94e2-a153b9fdadd6 没有创建分支的权限。

  • 转到存储库 -> 通过 Build/58bb64d7-d065-4522-94e2-a153b9fdadd6 之后给出的 Id 搜索用户 --> 即 58bb64d7-d065-4522-94e2-a153b9fdadd6 --> 并授予其贡献、拉取请求和标签。这有帮助。谢谢亲爱的 (2认同)