Getting Started With Jenkins-Installation and Setup
Firstly we will fulfill Jenkins’s requirements and then move towards Jenkins installation and then will create a Job, and at the end a must-watch Issues encountered Section. For android project related configuration read 2nd part.
Jenkins is a free and open-source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.
1) Jenkins Requirements (if already have, you can skip this part)
Jenkins is Java-based and can be installed from ubuntu packages.
- Java 8 runtime environments, both 32-bit and 64-bit versions are supported, Java 11 runtime environments are also supported
- Older versions of Java are not supported, Java 9, Java 10, Java 12 also not supported
So we need either of these OpenJDK JDK / JRE 8–64 bits or OpenJDK JDK / JRE 11–64 bits
So I decided to go with java 8, Let’s begin with getting requirements sorted first
sudo apt-get install openjdk-8-jre openjdk-8-jdk
now let’s set java Home
echo $JAVA_HOME
if this outputs nothing, we need to set Java Home variable
cd /usr/lib/jvm
cd java-8-openjdk-amd64
pwd
Check if bin folder is there, if yes run below command and copy the path
let’s export and check the path provided
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
echo $JAVA_HOME
now we have to set the path variable
export PATH=$PATH:$JAVA_HOME/bin
to set it permanently, open environment file in vi editor
(If familiar with VI Editor -> https://www.guru99.com/the-vi-editor.html)
vi /etc/environment
write this in file at the end -> JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 (depends on your installation)
source /etc/environment
(you can also add the path in your bash rc file if that doesn’t work for you
<sudo vi ~/.bashrc>)
2) Jenkins installation
Firstly Add Jenkins Repository key to the system, it will add key in the apt-key package.
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
Let’s add binaries now
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
Update and get Jenkins
sudo apt-get updatesudo apt-get install jenkins
If It throws unable to start error, as jenkins currently works on java version 8 and 11, you will have to set the correct version. Don’t Worry just run below command.
sudo update-alternatives --config java
Now choose java 8 option from the list given and Rerun Jenkins install command.
Open Web Browser and hit
localhost:8080
If nothing opens, please verify or change port assigned to Jenkins, you can also change it to 8081 or any other by opening the below file in VI editor.
cat /etc/default/jenkins
WOhooo It starts, lets fetch initial password to proceed further , paste and continue
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
I choose the first option, to install some suggested plugin
Set Up user
Now it will show you your Jenkins host address that is nothing but you localHost
3) Creating a Job
Click on New Item, Enter an Item name, choose Freestyle project
Scroll to Bottom, Set Build to Execute shell (as we trying a shell command)
In Description, I Wrote an echo statement
echo "bella ciao"
then apply, your project is ready now, press the Build button, and here is your output
4) Issues Encountered
- Ubuntu Release Support — I was on 19.04 (Disco Dingo) and its support ended, therefore, I was not able to run sudo apt-get update or install JDK. It was showing 404 on fetching update repositories. the found solution here -https://smyl.es/how-to-fix-ubuntudebian-apt-get-404-not-found-package-repository-errors-saucy-raring-quantal-oneiric-natty/
sudo sed -i -e 's|disco|eoan|g' /etc/apt/sources.list
I ran above command to move from 19.04(disco Dingo) to 19.10 (Eoan)
- If the old version of JDK set, we need to change the preference as Jenkins need 8 or 11.(sudo update-alternatives — config java)
- Jenkins Active port (cat /etc/default/jenkins)
For Android Configuration on Jenkins Read :
Part 2: Configuring Android Project on Jenkins
References