Could not push to git from shell in Jenkins job

22 views
Skip to first unread message

Alexey Lukin

unread,
Mar 29, 2017, 4:22:21 AM3/29/17
to jenkins...@googlegroups.com
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

--

Alexey Lukin
Ruby on Rails developer

skype:real_virtuoz

Alexey Lukin

unread,
Mar 29, 2017, 8:36:03 AM3/29/17
to Jenkins Users

The solution is to create id_rsa file manually in shell like this:

cat <<EOF >/root/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
content of the file
-----END RSA PRIVATE KEY-----
EOF
chmod 400 ~/.ssh/id_rsa

среда, 29 марта 2017 г., 11:22:21 UTC+3 пользователь Alexey Lukin написал:
Reply all
Reply to author
Forward
0 new messages