Continuous Integration With Jenkins on Alibaba Cloud
See how to set up, install, and run Jenkins, a continuous integration delivery environment, on an Alibaba Cloud Elastic Compute Service (ECS) Ubuntu instance.
Join the DZone community and get the full member experience.Join For Free
In this tutorial, we'll show you how to set up, install, and run Jenkins, a continuous integration delivery environment, on an Alibaba Cloud Elastic Compute Service (ECS) Ubuntu instance.
What Is Alibaba Cloud's Elastic Compute Service (ECS)?
Alibaba Cloud's Elastic Compute Service (ECS) is a range of elastic cloud-based server products that are simpler and more efficient to manage than physical servers. You can create instances, add memory and storage, scale up whenever you need to, build out complex and connected VPCs in different regions, and use them as essential components of Alibaba Cloud's vast range of cloud products and services.
What Is Jenkins?
Jenkins is a continuous integration build tool that builds and releases application code after any change is made to the code and pushed to the code base. Jenkins saves development time by running automated testing against the code at every change pushed to the repos. Nasty bugs are picked up immediately, and the whole team is aware of build failures as they happen.
Jenkins is an open source CI tool — just one of several open source and proprietary continuous integration build tools. You can use Jenkins as a simple CI server, but more often, it serves as the central continuous delivery hub for large projects.
Continuous integration tools solve problems associated with fragmented workflow as programmers and developers on large teams make changes to separate parts of the application code at the same time. Unforeseen issues show up incredibly quickly, allowing teams to deal with build failures efficiently and before they are able to cause further issues to the applications as more changes are added.
Jenkins is extensible and offers a wide range of plugins in order for it to integrate with every product in the continuous integration and delivery world.
You will need an Alibaba Cloud account. If you don't already have one, head over to the Free Trial page to get $300-1200 worth of Alibaba Cloud products to play around within the Alibaba Cloud Free Trial.
Let's go ahead and install Jenkins on an Alibaba Cloud Ubuntu ECSs.
Build and Configure an Alibaba Cloud ECS Instance
First, let's spin up an Alibaba Cloud ECS instance in our favorite region. Click through to the Elastic Compute Service product page.
In your favorite region, click Create Instance.
Select your Basic Configuration details and click Next: Networking.
We picked the latest version of Ubuntu for our operating system.
On the Networking page, make sure to assign a public IP address, and open the HTTP and HTTPS ports in the Security Group for the instance.
When you're ready, click through to System Configurations.
In the System Configurations page, set a password for root access or a key pair.
Leave Grouping as it is and click through to Preview.
On the Preview page, check all the ECS configuration details, agree to terms, and click Create Instance.
You will see a success message. Click back to Console.
You will see your instance starting up in the instances list. Make a note of the public IP.
When the instance is up and running, you can access it via ssh and do the software installations from the terminal.
Install Java on Ubuntu 18.04
Jenkins runs on Java, so we need to have Java installed. Connect to your instance via ssh.
Update the instance.
Install Java 8.
apt install openjdk-8-jre-headless
Check that you have installed Java Runtime Environment correctly.
Now install the Java Development Kit.
apt install openjdk-8-jdk
Make sure you've installed the JDK correctly.
Now update and upgrade your packages.
apt update apt upgrade
JAVA_HOME environment variable. First, check the available paths.
update-alternatives --config java
Next, open the environment file and add the path variable.
nano /etc/environment JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/"
Reload the file to apply the changes.
Check that the variable is set correctly.
Update the installation for good measure.
Now we're ready to install Jenkins.
Install Jenkins on Ubuntu
Connect to your instance via ssh.
Let's create a non-root user.
Give the new user administrative sudo privileges
usermod -aG sudo jenkins_user
Now we'll add a firewall to the instance, enable it, and check that the firewall is active.
ufw allow OpenSSH ufw enable ufw status
Now we're ready to install Jenkins. First, add the repository key to the packages.
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add –
Append the Debian package repository address to the instance's
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
Now update and install Jenkins.
apt update apt install jenkins
Let's start the Jenkins service and check its status.
sudo systemctl start jenkins sudo systemctl status jenkins
By default, Jenkins runs on port 8080. Open the port with ufw and check status.
sudo ufw allow 8080
Check Jenkins logs.
tail -f /var/log/jenkins/jenkins.log
Open port 8080 inbound and outbound in the Security Group for the instance.
Restart the instance. Once the instance is running again, you will be able to access Jenkins via the public IP and port 8080. Go to a browser window and input the following:
http://<<Public IP Address>>:8080
Follow the onscreen instructions to set up Jenkins.
Find the administrator password and enter it — make sure you keep a note of it.
We'll install the suggested plugins.
You will see the details of the plugin installation process.
When completed, you will be asked to set up a Jenkins user, but you can continue as admin.
We continued as the admin user.
Now save the Jenkins URL.
You can now start using Jenkins.
If you see a blank screen, restart Jenkins.
sudo service jenkins stop sudo service jenkins start
Now you can login with the administrator details and start creating jobs.
Go ahead and set up your project's releases to be managed by Jenkins.
To summarize, we showed you how to create an ECS Ubuntu 18.04 instance, how to login to it with ssh, and how to install Java and Jenkins. Finally, we confirmed that we had installed Jenkins correctly via a browser window and performed the initial set up.
Published at DZone with permission of Leona Zhang. See the original article here.
Opinions expressed by DZone contributors are their own.