1

I've got a project that I wan to build with Jenkins. The project is hosted in a private GitHub repo and I've put the SSH public key in GitHub of my user "deploy".

The project gets checked out fine thanks to the deploy credential in Jenkins git plugin section in the build config. But a vendor lib which is hosted as private in same GitHub organisation is loaded via a build step command :

php composer.phar install -o --prefer-dist --no-dev

I've installed Jenkins git plugin in order to checkout the main repo from GitHub via private SSH key. But when the composer tries to checkout the sub project I get

Failed to clone the git@github.com:Organisation/Repo.git repository, try running in interactive mode so that you can enter your GitHub credentials

I've tried to get the composer command ran as a different user without success with stuff like :

su - deploy -c 'php composer.phar install -o --prefer-dist --no-dev'

looks weird anyway. I'd like to figure out the proper way of having the composer doing his job. Thought ?

Jerem
  • 460
  • 5
  • 13
  • For info I found some kind of workaround. Executing a shell script as another user in JENKINS-CI https://fixitagain.wordpress.com/2011/07/29/executing-a-shell-script-as-another-user-in-jenkins-ci/ – Jerem Feb 05 '15 at 18:42

1 Answers1

3

Jenkins is actually running the shell commands as "jenkins" user. It means that "jenkins" needs access to GitHub. Then all the git@github.com:Organisation/Repo.git will work without additional credentials.

Here is explained how to grant Jenkins access to GitHub over SSH

# Login as the jenkins user and specify shell explicity,
# since the default shell is /bin/false for most
# jenkins installations.
sudo su jenkins -s /bin/bash

ssh-keygen -t rsa -C "your_email@example.com"
# Copy ~/.ssh/id_rsa.pub into your Github

# Allow adding the SSH host key to your known_hosts
ssh -T git@github.com

# Exit from su
exit

Inspired from: Managing SSH keys within Jenkins for Git

Community
  • 1
  • 1
Jerem
  • 460
  • 5
  • 13