【问题标题】:Commit files into azure git repo using azure devops使用 azure devops 将文件提交到 azure git repo
【发布时间】:2021-05-25 20:34:34
【问题描述】:

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

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

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

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

【问题讨论】:

标签: azure-devops azure-devops-pipelines azure-git-deployment


【解决方案1】:

对于经典模式管道:

您可以启用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 管道:

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

并为 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'

更多详细信息,您可以参考this ticket。

【讨论】:

【解决方案2】:

请确保Project Collection Build Service Accounts 和<repo> Build Service (<org>) 在Contribute 部分中都有Allow:

假设你已经完成了所有步骤Run Git commands in a script你应该准备好了。请注意,文档说您应该设置Project Collection Build Service,但也需要设置Project Collection Build Service Accounts。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    相关资源
    最近更新 更多