As a developer, often you are blocked by repetitive tasks that need be done. This is something that can become frustrating, but luckly we have some tools to help. In the following lines we will talk about Jenkins, an automation server written in Java.
Assumptions
- Your Ubuntu has a public IP address
- Your sudo username is:
admin - Your host is:
jenkins.example.com - You have a cname DNS entry for every subdomain of
jenkins.example.compointing to itself.
The setup
Please note that there are commands which are not mandatory and everything can be adapted to the needs of your system (e.g. You might choose not to use nginx)
Sudo user
sudo apt-get updateadduser adminusermod -aG sudo adminsudo passwd -l rootsu - admin
The locale
localesudo apt-get install language-pack-en-basesudo dpkg-reconfigure locales
Swap
If using digitalocean, swap is not recommended.
sudo swapon --showsudo fallocate -l 4G /swapfilels -lh /swapfilesudo chmod 600 /swapfilels -lh /swapfilesudo mkswap /swapfilesudo swapon /swapfilesudo swapon --show
Make swap permanent
sudo nano /etc/fstab
and add at the end:/swapfile none swap sw 0 0
Firewall
sudo ufw allow 8080sudo ufw allow OpenSSHsudo ufw enable
Setup java
sudo apt-get install default-jre
Jenkins
sudo apt-get install jenkinssudo systemctl start jenkinssudo systemctl status jenkinssudo nano /var/lib/jenkins/secrets/initialAdminPassword- Access `http://jenkins.example.com:8080/` to finish setup.
"Package 'jenkins' has no installation candidate"
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'sudo apt-get update
"ubuntu 18.04 jenkins found an incorrect java version"
sudo add-apt-repository ppa:webupd8team/javasudo apt install oracle-java8-installerwget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -sudo apt-add-repository "deb https://pkg.jenkins.io/debian-stable binary/"sudo apt install jenkins
nginx
sudo apt-get updatesudo apt-get install nginxsudo ufw allow 'Nginx HTTP'sudo add-apt-repository ppa:certbot/certbotsudo apt-get updatesudo apt-get install python-certbot-nginxsudo nano /etc/nginx/sites-available/default- replace `server_name _` with
server_name jenkins.example.com www.jenkins.example.com;
- replace `server_name _` with
sudo nginx -tsudo systemctl reload nginx
sudo ufw allow 'Nginx Full'sudo ufw delete allow 'Nginx HTTP'sudo certbot --nginx -d jenkins.example.com -d www.jenkins.example.com- Choose redirect all traffic to
https://
Use Jenkins with ssl nginx
sudo nano /etc/nginx/sites-available/default- find
try_files $uri $uri/ =404; - replace with:
# try_files $uri $uri/ =404; include /etc/nginx/proxy_params; proxy_pass http://localhost:8080; proxy_read_timeout 90s; # Fix potential "It appears that your reverse proxy set up is broken" error. proxy_redirect http://localhost:8080 https://jenkins.example.com;
- find
sudo nano /etc/default/jenkins- find
JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT" - replace with:
JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress=127.0.0.1"
- find
sudo systemctl restart jenkinssudo systemctl restart nginx- Go to:
https://jenkins.example.comand choose:Manage jenkins > Configure systemand updateJenkins location > Jenkins URLtohttps://jenkins.example.com.
Blueocean
For a better UI/UX experience, you could install the BlueOcean plugin, from the jenkins available plugins.
Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"sudo apt-get updateapt-cache policy docker-cesudo apt-get install -y docker-ce
Sources
- https://draghici.net/2018/03/03/setting-new-droplet-digitalocean-webmin-lamp-ssl/
- https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04
- https://www.digitalocean.com/community/tutorials/how-to-set-up-continuous-integration-pipelines-in-jenkins-on-ubuntu-16-04
- https://wiki.jenkins.io/display/JENKINS/Docker+Custom+Build+Environment+Plugin
- https://www.youtube.com/watch?v=WWcijE7ifcA&list=PLzvRQMJ9HDiSaisKr7OnM4Fl7JXCDDcmt

