Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit files into azure git repo using azure devops

how to commit files into azure git repo using build pipeline.

I am generating some files from my azure ci pipeline and I want to commit those files into the same repo which I used in my ci pipeline.

I have added the azure CLI task and added an inline command to commit code but it gives me the error and not working.

git add .
git commit -m "test commit"
git push -u origin Trunk
like image 222
Jaydeepsinh Avatar asked Apr 28 '26 11:04

Jaydeepsinh


1 Answers

For classic Mode pipeline:

You could enable the Allow scripts to access the OAuth token option.

enter image description here

And grant the Repo Contribute permission for Project Collection Build Service Accounts.

enter image description here

Git command:

   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

For Yaml Pipeline:

You could set the persistCredentials: true in YAML sample.

And grant the Repo Contribute permission for Build Service .

enter image description here

Yaml Sample:

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'

For more detailed info, you could refer to this ticket.

like image 164
Kevin Lu-MSFT Avatar answered May 01 '26 23:05

Kevin Lu-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!