×
Community Blog Continuous Integration with Jenkins on Alibaba Cloud

Continuous Integration with Jenkins on Alibaba Cloud

In this tutorial, we'll show you how to set up a continuous integration delivery environment on an Alibaba Cloud ECS Ubuntu instance using Jenkins.

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 which 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 a large choice of 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.

Prerequisites

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 with in 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.

1

In your favorite region, click Create Instance.

2

Select your Basic Configuration details and click Next: Networking.

3

We picked the latest version of Ubuntu for our operating system.

4

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.

5

In the System Configurations page, set a password for root access, or a key pair.

6

Leave Grouping as it is and click through to Preview.

7

On the Preview page, check all the ECS configuration details, agree to terms, and click Create Instance.

8

You will see a success message. Click back to Console.

9

You will see your instance starting up in the instances list. Make a note of the public IP.

10

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.

11

Update the instance.

apt update

Install Java 8.

apt install openjdk-8-jre-headless

Check you have installed Java Runtime Environment correctly.

java -version

Now install the Java Development Kit.

apt install openjdk-8-jdk

Make sure you've installed the JDK correctly.

java -version

Now update and upgrade your packages.

apt update

apt upgrade

Set the 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/"

12

Reload the file to apply the changes.

source /etc/environment

Check the variable is set correctly.

echo $JAVA_HOME

Update the installation for good measure.

apt update

Now we're ready to install Jenkins.

Install Jenkins on Ubuntu

Connect to your instance via ssh.

Let's create a non-root user.

adduser jenkins_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 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 sources.list.

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

13

By default, Jenkins runs on port 8080. Open the port with ufw and check status.

sudo ufw allow 8080

14

Check Jenkins logs.

tail -f /var/log/jenkins/jenkins.log

15

Open port 8080 inbound and outbound in the Security Group for the instance.

16

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

17

Follow the onscreen instructions to set up Jenkins.

Find the administrator password and enter it – make sure you keep a note of it.

nano /var/lib/Jenkins/secrets/initialAdminPassword

18

We'll install the suggested plugins.

19

You will see details of the plugin installation process.

20

When completed, you will be asked to set up a Jenkins user, but you can continue as admin.

We continued as the admin user.

21

Now save the Jenkins URL.

22

You can now start using Jenkins.

23

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.

24

25

Go ahead and set up your project's releases to be managed by Jenkins.

Summary

To summarize, we told you about Alibaba Cloud's Elastic Compute Service (ECS) and Jenkins continuous integration build tool. 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.

Keep your eye out for more tutorials on Alibaba Cloud's products and services at www.alibabacloud.com/blog.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 758 followers

You may also like

Comments