Jenkins: Git & GitHub
Jenkins
The most basic function of any Continuous Integration tool is to monitor source code in a version control system and to fetch and build the latest version of our source code whenever any changes are committed. So we'll need a version control system. In our case, we'll be using Git. The central source code repository for our simple project is stored on GitHub.
Download the latest stable git:
$ sudo apt-get install git $ which git /usr/bin/git $ git --version git version 1.9.1
In our Jenkins console, goto 'Manage Jenkins -> Manage Plugins' from the home screen. Open the 'Available' tab and find the plugin entitled Git Plugin:
This will download and install the Jenkins Git plugin into our local Jenkins instance.
The Jenkins GitHub plugin provides support for receiving push notifications from Github post-commit hooks and using those notifications to trigger jobs within Jenkins. It can setup the post-commit hooks in GitHub for us.
Also, GitHub decorates the Jenkins "Changes" pages with links to the pretty GitHub commit, issues pages and adds a sidebar link to the corresponding GitHub project page.
$ sudo service jenkins restart
We will need to create a GitHub account:
GitHub uses SSH keys to establish a secure connection between our computer and the GitHub servers.
SSH keys are a way to identify trusted computers, without involving passwords. The steps in the link below will walk us through generating an SSH key and then adding the public key to our GitHub account.
$ ssh-keygen -t rsa -C "devops@bogotobogo.com"
Then copy the public key file (~/.ssh/id_rsa.pub) and paste it onto the 'key" field of Github as described below:
Now that we have the public key copied, it's time to add it to GitHub:
- In the top right corner of any page, click 'Settings' icon.
- In the user settings sidebar, click 'SSH keys'.
- Click 'New SSH key'.
- In the Title field, add a descriptive label for the new key.
- Paste our key into the "Key" field.
- Click 'Add key'.
- Confirm the action by entering our GitHub password.
To make sure everything is working, we may want to try SSHing to GitHub. When we do this, we will be asked to authenticate this action using our password, which was the passphrase we created earlier.
Open up Terminal and type:
$ ssh -T git@github.com ... Hi bogo-devops! You've successfully authenticated, but GitHub does not provide shell access.
If that username is correct, we've successfully set up our SSH key! Don't worry about the "shell access" thing, we don't want that anyway.
For more on fork, visit GitHub Fork/Clone & Origin/Upstream.
Let's go to "https://github.com/wakaleo/game-of-life". This is a public repository, so we can freely view the source code online and check out our own working copy. However, if we want to make changes, we will need to create our own fork. A fork is a personal copy of a repository that we can use as we wish. Let's do fork:
Now we have forked it:
Once we have forked the repository, we should clone a local copy to make sure everything is set up correctly.
The url to clone is available from "HTTPS clone URL" text box:
Go to the command line and run the following command:
$ sudo git clone https://github.com/bogo-devops/game-of-life.git
We now have a local copy of the project that we can build and execute. We will be using this project later on to trigger changes in the repository.
Jenkins
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization