Continuous integration is one of the key parts of the modern software development process. Today we will set up the integration of the popular jenkins automation server with the private repositories of the Github service.
I assume that you already have an account on the Github service and have jeknins server configured.
Adding ssh private key to jenkins
Let’s add our ssh key to the jenkins parameters. Follow the links Credentials> jenkins> Global credentials. In the dropdown list, select the option ‘SSH username with private key’ to add the ssh key and fill in all the fields.
Checkout private Github repo from pipeline job
Let’s create a new pipeline job. I will use the declarative pipeline syntax in jenkins script. Add the following line to check the checkout git repo.
Let’s run our pipeline. It’s successfully completed!
Check the logs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
Started by user username Running in Durability level: MAX_SURVIVABILITY [Pipeline] node Running on Jenkins in /var/jenkins_home/workspace/github-clone [Pipeline] { [Pipeline] stage [Pipeline] { (Checkout) [Pipeline] git <strong>Cloning the remote Git repository Cloning repository git@github.com:username/checkstyle.git</strong> > git init /var/jenkins_home/workspace/github-clone # timeout=10 Fetching upstream changes from git@github.com:username/checkstyle.git > git --version # timeout=10 <strong>using GIT_SSH to set credentials github-ssh</strong> > git fetch --tags --progress git@github.com:username/checkstyle.git +refs/heads/*:refs/remotes/origin/* > git config remote.origin.url git@github.com:username/checkstyle.git # timeout=10 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10 > git config remote.origin.url git@github.com:username/checkstyle.git # timeout=10 Fetching upstream changes from git@github.com:username/checkstyle.git using GIT_SSH to set credentials github-ssh > git fetch --tags --progress git@github.com:username/checkstyle.git +refs/heads/*:refs/remotes/origin/* > git rev-parse refs/remotes/origin/master^{commit} # timeout=10 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10 <strong>Checking out Revision 6a8ac668eab396448ab7c5e2be100f2abf9f0348</strong> (refs/remotes/origin/master) > git config core.sparsecheckout # timeout=10 > git checkout -f 6a8ac668eab396448ab7c5e2be100f2abf9f0348 > git branch -a -v --no-abbrev # timeout=10 > git checkout -b master 6a8ac668eab396448ab7c5e2be100f2abf9f0348 Commit message: "init commit" First time build. Skipping changelog. [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline <strong>Finished: SUCCESS</strong> |
Yes, everything worked, we cloning the project from a private Github repository and we can start working with it.