git - 从 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
同样,它在构建管道中有效,但在发布管道中无效。
解决方案
-- 开始编辑 -- 您需要为此身份'Build**58bb64d7-d065-4522-94e2-a153b9fdadd6** 授予通用贡献权限。
- 在 azure devops 中转到项目设置
- 转到 repos -> repositories -> 点击你的 repo
- 在安全选项卡上, 在“搜索用户和组”上浏览 ID 58bb64d7-d065-4522-94e2-a153b9fdadd6
- 单击找到的身份并确保它具有:贡献权限、创建分支、创建标签和读取权限设置为允许
- - 编辑 - -
构建管道是否也在自托管构建服务器上运行?
转到您的构建管道-> 变量-> 检查 system.collectionId。
是 58bb64d7-d065-4522-94e2-a153b9fdadd6 吗?
如果这不是您的构建管道中的集合 ID,则表示您的发布管道中的身份 58bb64d7-d065-4522-94e2-a153b9fdadd6 没有创建分支的权限。
推荐阅读
- r - r 中的嵌套 for 循环错误(包 extRemes)
- javascript - 为什么当我在 app.js 上使用控制台登录时它会得到未定义的返回?
- vb.net - 循环遍历空文本框,直到文本框有数据
- bash - 从脚本中的字符串获取纪元
- algorithm - BST(方案)中的第 K 个最小元素
- c# - 为什么我的玩家生命没有在每次屏幕加载时重置?
- c# - 你如何从另一个方法的代码中结束一个方法?
- python - GNUPG - 文件夹名称中的空格问题
- java - 如何在没有 main 方法的情况下在终端中测试我的代码?
- kubernetes - GKE Config Connector StorageBucket 资源在 kubectl apply 上超时