首页 > 解决方案 > 从 Azure 发布管道执行 Git 推送

问题描述

我想在自托管构建服务器的 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'.

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

$ 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

同样,它在构建管道中有效,但在发布管道中无效。

标签: gitazure-devopsazure-pipelines

解决方案


-- 开始编辑 -- 您需要为此身份'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 没有创建分支的权限。


推荐阅读