I need to use jenkins job to synchronize two repositories. So I have created a job, added two git repositories using Multiple SCMs plugin.
And added shell commands, example:
cd first_project
sha=`cat last_commit_merged`
cd ..
cd second_project
new_sha=`git rev-parse HEAD`
git diff-index "$sha" --binary > my.patch
cd ..
cd first_project
if [ "$sha" != "$new_sha" ]
then
git apply ../second_project/my.patch
echo "$new_sha" > last_commit_merged
git add .
git commit -m "New sync, date `date +'%Y-%m-%d %H:%M:%S'`";
git push origin HEAD
fi
So when job starts, it successfully clones both repositories in folders: first_project and second_project, I could create my.patch, apply it and commit, but command: git push origin HEAD does not work and I could not figure out how to setup correctly git in shell to make it working, the error is:
+ git push origin HEAD
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
If anyone could help that would be much appreciated
Thanks