错误日志
remote: 001f# service=git-receive-pack remote: 0000000000aaTF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\8b517d3f-052b-41e0-a7f6-e811999734c0', scope 'repository'. remote: TF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\8b517d3f-052b-41e0-a7f6-e811999734c0', scope 'repository'. fatal: unable to access 'https://dev.azure.com/zuzhi/China-iTwin/_git/testforYanjun/': The requested URL returned error: 403
错误如下图:
解决:
Azure DevOps Services |Azure DevOps Server 2022 - Azure DevOps Server 2019 |TFS 2018
对于某些工作流,需要生成管道才能运行 Git 命令。 例如,在功能分支上生成 CI 后,团队可能需要将分支合并到主分支。
Git 适用于 Microsoft 托管的代理 和 本地代理。
启用脚本以运行 Git 命令
备注
在开始之前,请确保帐户的默认标识已使用以下代码进行设置。 在签出代码后,必须首先完成此操作。
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
向生成服务授予版本控制权限
-
在 “组织设置>常规>项目”中转到组织的项目设置页面。
-
选择要编辑的项目。
-
在 “项目设置”中,选择 “存储库”。 选择要在其中运行 Git 命令的存储库。
-
选择 “安全性 ”以编辑存储库安全性。
-
搜索 项目集合生成服务。 选择标识 项目集合生成服务 ({你的组织}) (不是组 Project Collection Build Service Accounts ({your organization}) ) 。 默认情况下,此标识可以从存储库读取,但无法将任何更改推送回存储库。 授予要运行的 Git 命令所需的权限。 通常,你需要授予:
- 创建分支: 允许
- 贡献: 允许
- 读: 允许
- 创建标记: 允许
允许脚本访问系统令牌
确保清理本地存储库
生成管道不会自动清理对本地存储库的某些类型的更改。 因此,请确保:
- 删除创建的本地分支。
- 撤消 git 配置更改。
如果使用本地代理遇到问题,请确保存储库干净:
参考链接:Run Git commands in a script - Azure Pipelines | Microsoft Learn