1

I have cloned remote GitHub repository into my Build Server. A build definition in VSTS generated a file as build artifact. I copy that file into local github repository in build server through a powershell script task in VSTS. I want to run Git commands to push this new build artifact file from local github repository to remote GitHub repository. I have stored batch file with Git commands on build server. When a build runs on VSTS, I try to invoke batch file residing in build server through a "Command Line Script" VSTS task.

Command Line Script:

cd "batch file path"
GitCommands.bat

Now I keep getting errors related to git commands in batch file. Below is an example.

Note: I am trying to push a single file directly to github repository using git commands in batch file.

2018-08-30T20:17:07.9089221Z On branch master
2018-08-30T20:17:07.9090417Z Your branch is up to date with 'origin/master'.
2018-08-30T20:17:07.9166091Z 
2018-08-30T20:17:07.9180427Z Untracked files:
2018-08-30T20:17:07.9205244Z   (use "git add <file>..." to include in what will be committed)
2018-08-30T20:17:07.9224271Z 
2018-08-30T20:17:07.9298112Z    filename.ipa
2018-08-30T20:17:07.9316134Z 
2018-08-30T20:17:07.9457726Z nothing added to commit but untracked files present (use "git add" to track)
2018-08-30T20:17:10.4572412Z fatal: Unable to write new index file
2018-08-30T20:17:10.4614209Z file added
2018-08-30T20:17:10.5106172Z On branch master
2018-08-30T20:17:10.5107096Z Your branch is up to date with 'origin/master'.
2018-08-30T20:17:10.5131465Z 
2018-08-30T20:17:10.5145982Z Untracked files:
2018-08-30T20:17:10.5184825Z    filename.ipa
2018-08-30T20:17:10.5204032Z 
2018-08-30T20:17:10.5280428Z nothing added to commit but untracked files present
2018-08-30T20:17:38.9087093Z Terminate batch job (Y/N)? 

Batch file content:

*cd to github loval repository

git status

git add .

echo file added

git commit -m "Adding ipa file to the repository through VSTS automated build"

git push origin master*
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
jay
  • 119
  • 3
  • 12
  • It's due to some lock [here](https://stackoverflow.com/questions/16064513/git-fatal-unable-to-write-new-index-file) the solution is – Jayendran Aug 31 '18 at 02:11

1 Answers1

0

You can use a PowerShell task to replace the Command Line task. The PowerShell script should be:

cd \path\to\local\github\repo
git status
git add .
echo "file added"
git commit -m "Adding ipa file to the repository through VSTS automated build"
git push https://username:password@github.com/username/reponame master

Then you should commit and push the new added file successful to github repo.

Note: You need to provide credential (username and password) when pushing changes to github.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74