Friday, August 10, 2012

Jenkins

How to start with jenkins?
1. Installation on CentOS:
# sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
# sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
# sudo yum install jenkins

2. Start Jenkins
The easiest way to execute Jenkins is through the built in Winstone servlet container. You can execute Jenkins like this:
# java -jar jenkins.war
To see Jenkins UI, open a web browser and go to URL http://myServer:8080 where myServer is the name of the system running Jenkins, for example: localhost or 127.0.0.1

3.  Configure Jenkins
Go to >Manage Jenkins >Manage Plugins.
Choose github plugin and git plugin to be installed.
Go to >Manage Jenkins >Configure System
    Security Realm:
    choose Jenkins's own user database, and then choose Allow users to sign up.
    Authorization:
    choose Matrix-based security, and add user or group.
    JDK:
    if JDK is already installed, just need to fill in JAVA_HOME, or you can choose install  automatically.
    Git:
    if git is already installed, just leave the name default and fiil "git " in the box of path to git executable, or install it automatically.
    Maven:
    if Maven is already installed, just fill in MAVEN_HOME, or install automatically.
After all those are finished, press save, the configuration step is done.


How to Create Jenkins User?
1. Create jenkins user.
#sudo /usr/sbin/useradd -m jenkins -d /home/jenkins
2. Checkout jenkins user information.
# id jenkins
it looks like this:
uid=506(jenkins) gid=506(jenkins) groups=506(jenkins);
3. Work as a jenkins user.
# su jenkins OR su-jenkins
4. Set jenkins user password.
# sudo /usr/bin/passwd jenkins


HOWTO connect Jenkins with PRIVATE GitHub Repo?


1. su as a jenkins user to create the SSH key pair.
if you don't know your jenkins user password, you can reset it as following :
#sudo /usr/bin/passwd jenkins

2. Create SSH Key:

ssh-keygen is used to generate that key pair for you.
Here is a session where your own personal private/public key pair is created:
# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cantin/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/cantin/.ssh/id_rsa.
Your public key has been saved in /home/cantin/.ssh/id_rsa.pub.
The key fingerprint is:
f6:61:a8:27:35:cf:4c:6d:13:22:70:cf:4c:c8:a0:23 cantin@sodium

Explanation: 
The command ssh-keygen -t rsa initiated the creation of the key pair.
No passphrase was entered (Enter key was pressed instead).
The private key was saved in .ssh/id_rsa. This file is read-only and only for you. No one else must see the content of that file, as it is used to decrypt all correspondence encrypted with the public key.
The public key is save in .ssh/id_rsa.pub.

3. Paste the content of id_rsa.pub to your Github account. 

# cat id_rsa.pub  [show the public key onscreen]
(1) Copy the public key, go to GitHub, you'll see Account setting on the upper right, press it and you'll see SSH Keys, then paster the key here!
(2) An alternative way is Deploy key to a specific repo.  You don't paste the key to account this time, go to specific repo, press Admin, and choose Deploy key.
Now, it should work.

No comments:

Post a Comment