1. Install Jenkins
We'll login using my local AWS-generated ssh key:
ssh -i ~/.ssh/fideloperllc.pem ubuntu@<server-ip>
Then we start installing:
# Install some Basics:
sudo apt-get update
sudo apt-get install -y vim curl wget tmux unzip htop ntp software-properties-common
# Install Jenkins
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
echo 'deb http://pkg.jenkins.io/debian-stable binary/' | sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt-get update
sudo apt-get install -y jenkins
# Status (Start Jenkins if necessary)
sudo service jenkins status
# Test It
curl localhost:8080
2. Install Nginx
We can view this in a browser yet, since port 8080
isn't publicly accessible from this server. Let's install Nginx and use that as our HTTP entry point for this. It will proxy requests over to Jenkins.
sudo add-apt-repository -y ppa:nginx/stable
sudo apt-get update
sudo apt-get install -y nginx
Configure Nginx
sudo rm /etc/nginx/sites-enabled/default
sudo vim /etc/nginx/sites-available/jenkins
Make it like so:
server {
listen 80 default_server;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_buffers 4 32k;
client_max_body_size 8m;
client_body_buffer_size 128k;
}
}
Then enable it:
sudo ln -s /etc/nginx/sites-available/jenkins \
/etc/nginx/sites-enabled/jenkins
Test and reload Nginx:
sudo service nginx configtest
sudo service nginx reload
Jenkins should now be web accessible!
3. Unlock Jenkins
Follow the steps to unlock Jenkins:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Use that password in the browser to create a new user.
- Install suggested plugins.
Note the
GitHub Organization Folder Plugin
plugin, theGit plugin
, andpipeline viewer
plugin.
New Jenkins User
- fideloper
- Some Password
4. Docker
We'll use Docker on this Jenkins server, so let's go ahead and install it.
# Install Latest Stable Docker
curl -sSL https://get.docker.com/ | sudo sh
# Ensure "jenkins" user can use it without "sudo",
# since we'll be automating jenkins with Docker
sudo usermod -aG docker jenkins
docker ps
docker docker ps
sudo -u jenkins docker ps
# Install Latest Release `docker-compose`
sudo su
curl -L https://github.com/docker/compose/releases/download/1.10.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
exit
5. Restart Jenkins
We need to restart Jenkins so it picks up the addition of group docker
to user jenkins
.
sudo service jenkins restart
Resources
- Install Jenkins on RedHat/CentOS: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Red+Hat+distributions
- Install Jenkins on Debian/Ubuntu: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
- Install
docker-compose
: https://github.com/docker/compose/releases
If you're interested in learning more about Docker and how I use Jenkins with a Docker workflow, check out the ? Shipping Docker series!