1

如何使用构建管道将文件提交到 azure git repo。

我正在从我的 azure ci 管道生成一些文件,我想将这些文件提交到我在 ci 管道中使用的同一个存储库中。

我添加了 azure CLI 任务并添加了一个内联命令来提交代码,但它给了我错误并且无法正常工作。

git add .
git commit -m "test commit"
git push -u origin Trunk
4

2 回答 2

2

对于经典模式管道:

您可以启用该Allow scripts to access the OAuth token选项。

在此处输入图像描述

并授予Project Collection Build Service Accounts的 Repo Contribute权限。

在此处输入图像描述

git命令:

   git config --global user.email "email"
   git config --global user.name "Kevin Lu"

   git add .

   git commit -m "My commit message"

   git push origin master

对于 Yaml 管道:

您可以persistCredentials: true在 YAML 示例中设置。

并授予Build Service的 Repo Contribute权限。

在此处输入图像描述

Yaml 示例:

steps:
- checkout: self
  persistCredentials: true

- script: |
   git config --global user.email "email"
   git config --global user.name "Kevin Lu"
       
   git add .
   
   git commit -m "My commit message"
   
   git push origin master
   
  displayName: 'Command Line Script'

更详细的信息,你可以参考这张票

于 2021-05-26T02:25:17.917 回答
0

请确保两者Project Collection Build Service Accounts<repo> Build Service (<org>)Allow部分中Contribute具有:

在此处输入图像描述

假设您已经完成了所有步骤在脚本中运行 Git 命令,您应该可以开始了。请注意,文档说您应该设置Project Collection Build Service,但也需要设置Project Collection Build Service Accounts

于 2021-05-26T02:07:33.447 回答