Setting up jenkins and Github:
Environment Details :
Operating System : Amazon Linux
AMI-ID : (ami-bba18dd2)
Make sure you do not have the default security group as it blocks the port 8080, which is the port on which jenkin runs.
Also select the security group before you launch the instance as AWS does not allow you to change the security group after you have launched the instance. (Unless you are inside a VPC)
Security group name: launch-wizard-jenkins-test.
It should look something like this
Launch the instance.
1)Login to the instance.
2) Become the root user. ‘sudo su’
3) Update the repositories
$ yum update
4) Get Jenkins repository using below command
$ wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
6) Install jenkins package
$ yum install jenkins
7) Start jenkins and make sure it starts automatically at system startup
$ service jenkins start
$ chkconfig jenkins on
8) Open your browser and navigate to http://<Elastic-IP>:8080. You will see jenkins dashboard.
Configuring Jenkins to run with Github using Github Oauth Plugin:
1) Browse to the jenkins instance you have installed and select Manage Jenkins.
2) Go to Manage Plugins on the Jenkins dashboard.
(Update any updates that are there and restart Jenkins.)
3) Select Available Tab and search for GitHub API Plugin
(* If you do not see any Available plugins loading up then select the Advance tab and in the bottom right hand corner click on the Check Now button
After this you should start seeing the available plugins for jenkins)
4) Install the GitHub plugin, Github Api Plugin, GitHub Authentication plugin. Let jenkins restart after that.
5) Once you have installed all the plugins go back to Mange Jenkins dashboard and select Configure System.
In configure system you may observe that Git is not installed. Just login to the instance and as a root user run this command.
$ yum install git
6) Now we need to create a rsa ssh-key and add the public key to your Github account so that jenkins can directly talk to github.
Login to the instance. Make sure you are the root user (sudo su)
Now you need to login as the Jenkins user and create ssh keys for that particular user.
As jenkins is a service account it does not have a shell by design. So as a root user switch to the jenkins user using this command.
$ su -s /bin/bash jenkins
$ cd ~/.ssh/
$ ssh-keygen -t rsa
(Do not enter any passphrase)
7) Add your public rsa key to GitHub
(Follow this url: https://help.github.com/articles/generating-ssh-keys)
8) Ssh to gitHub
$ssh -T email@example.com
This should be enough and you can start using GitHub to create jobs. The next part is setting up GitHub oauth login.
GitHub Oauth for Jenkins:
1) Go to your Github web account settings page.
2) Select the Applications Tab.
3) Click on the Register new application
4) Select a name for the Application. Give your jenkins Url. And the authorization call back URL.
The most important thing here is the authorization callback url. It should be like this
When you create the application it will generate a Client id and client secret.
5) Go back to your Jenkins on your browser and Manage jenkins -> Configure Global Security
6) Select Enable security.
7) Then in Security realm select Github Authentication Plugin and copy paste the client id and client secret generated before.