So this is going to be a relatively simple setup for how I set up and installed Jenkins on my server (jenkins.ceneblock.com) and how I have it integrated with github.
Jenkins is a build system that I use daily at my current job and at previous ones. It isn’t without flaws, but it has proven to be useful for finding bugs. It can be set up to not only build, but to run test suites, packaging, and all sorts of stuff that makes life really easy for end users.
I’m currently working on a hardware project and I want to write some APIs that abstract a lot of the lower level stuff for me, so that’s why I want to get Jenkins set up whenever I do a push on my repos.
First things first, we need to get the repo, enable it, and install Jenkins:
zypper addrepo -f https://pkg.jenkins.io/opensuse-stable/ jenkins
zypper in jenkins
Next, go ahead and start up Jenkins and set it to start on boot:
systemctl enable jenkins
systemctl start jenkins
When I tried this, I got the following errors in /var/log/jenkins.rc:
Sep 09, 2020 8:15:49 PM Main verifyJavaVersion
SEVERE: Running with Java class version 59 which is not in the list of supported versions: [52, 55]. Run with the --enable-future-java flag to enable such behavior. See https://jenkins.io/redirect/java-support/
java.lang.UnsupportedClassVersionError: 59.0
at Main.verifyJavaVersion(Main.java:174)
at Main.main(Main.java:142)
Jenkins requires Java versions [8, 11] but you are running with Java 15 from /usr/lib64/jvm/java-15-openjdk-15
java.lang.UnsupportedClassVersionError: 59.0
at Main.verifyJavaVersion(Main.java:174)
at Main.main(Main.java:142)
So let’s take a look at the link provided.
Java 8 runtime environments, both 32-bit and 64-bit versions are supported
Since Jenkins 2.164 and 2.164.1 [1], Java 11 runtime environments are supported
Running Jenkins with Java 11 is documented here
There are some precautions to take when upgrading from Java 8 to Java 11 in Jenkins, please follow these guidelines.
Older versions of Java are not supported
Java 9 and Java 10 are not supported
Java 12 is not supported
So I’m using too new of a version of Java…😬
Now I see why they recommend running it in Docker.
Okay, so let’s install an older version of Java and hope things don’t catch on fire.
zypper se openjdk Loading repository data... Reading installed packages... S | Name | Summary | Type --+----------------------------------+------------------------------------+-------- | java-11-openjdk | OpenJDK 11 Runtime Environment | package | java-11-openjdk-accessibility | OpenJDK 11 accessibility connector | package | java-11-openjdk-demo | OpenJDK 11 Demos | package | java-11-openjdk-devel | OpenJDK 11 Development Environment | package i | java-11-openjdk-headless | OpenJDK 11 Runtime Environment | package | java-11-openjdk-javadoc | OpenJDK 11 API Documentation | package | java-11-openjdk-jmods | JMods for OpenJDK 11 | package | java-11-openjdk-src | OpenJDK 11 Source Bundle | package | java-14-openjdk | OpenJDK 14 Runtime Environment | package | java-14-openjdk-accessibility | OpenJDK 14 accessibility connector | package | java-14-openjdk-demo | OpenJDK 14 Demos | package | java-14-openjdk-devel | OpenJDK 14 Development Environment | package | java-14-openjdk-headless | OpenJDK 14 Runtime Environment | package | java-14-openjdk-javadoc | OpenJDK 14 API Documentation | package | java-14-openjdk-jmods | JMods for OpenJDK 14 | package | java-14-openjdk-src | OpenJDK 14 Source Bundle | package i | java-15-openjdk | OpenJDK 15 Runtime Environment | package | java-15-openjdk-accessibility | OpenJDK 15 accessibility connector | package | java-15-openjdk-demo | OpenJDK 15 Demos | package i | java-15-openjdk-devel | OpenJDK 15 Development Environment | package i | java-15-openjdk-headless | OpenJDK 15 Runtime Environment | package | java-15-openjdk-javadoc | OpenJDK 15 API Documentation | package | java-15-openjdk-jmods | JMods for OpenJDK 15 | package | java-15-openjdk-src | OpenJDK 15 Source Bundle | package | java-1_8_0-openjdk | OpenJDK 8 Runtime Environment | package | java-1_8_0-openjdk-accessibility | OpenJDK 8 accessibility connector | package | java-1_8_0-openjdk-demo | OpenJDK 8 Demos | package | java-1_8_0-openjdk-devel | OpenJDK 8 Development Environment | package | java-1_8_0-openjdk-headless | OpenJDK 8 Runtime Environment | package | java-1_8_0-openjdk-javadoc | OpenJDK 8 API Documentation | package | java-1_8_0-openjdk-src | OpenJDK 8 Source Bundle | package
And install it:
zypper in java-11-openjdk java-11-openjdk-devel
Note: I am installing the corresponding devel as I found that that was part of some issues I had.
Now we can restart Jenkins, but if you’re still having trouble, then you may need to run update-alternatives --all
and manually select what version of java to use.
You may see something like the following:
There are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib64/jvm/jre-11-openjdk/bin/java 2105 auto mode * 1 /usr/lib64/jvm/jre-1.8.0-openjdk/bin/java 1805 manual mode 2 /usr/lib64/jvm/jre-11-openjdk/bin/java 2105 manual mode 3 /usr/lib64/jvm/jre-15-openjdk/bin/java 0 manual mode Pressto keep the current choice[*], or type selection number: There are 2 choices for the alternative javac (providing /usr/bin/javac). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac 1805 auto mode 1 /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac 1805 manual mode 2 /usr/lib64/jvm/java-15-openjdk/bin/javac 0 manual mode Press to keep the current choice[*], or type selection number: There is only one alternative in link group java_sdk_15 (providing /usr/lib64/jvm/java-15): /usr/lib64/jvm/java-15-openjdk Nothing to configure. There is only one alternative in link group java_sdk_1.8.0 (providing /usr/lib64/jvm/java-1.8.0): /usr/lib64/jvm/java-1.8.0-openjdk Nothing to configure. There are 2 choices for the alternative java_sdk_openjdk (providing /usr/lib64/jvm/java-openjdk). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib64/jvm/java-1.8.0-openjdk 1805 auto mode 1 /usr/lib64/jvm/java-1.8.0-openjdk 1805 manual mode 2 /usr/lib64/jvm/java-15-openjdk 0 manual mode
Despite this and a reboot, it still wanted to run Java 15, so I wound up editing /etc/sysconfig/jenkins
:
With Jenkins up and running, we’ll need to log into it.
By default it lives at http://localhost:8080
So first you’ll be presented to enter in an admin password followed by asking if you want to install the suggested plugins.
We’ll go ahead and do the defaults and let those install. In particular, it should automatically install GitHub which is what we’ll want.
Once that’s finished, it’ll prompt you to set up an administrator account.
You’ll then be prompted to set a URL, this should be some forward facing URL so in my case https://jenkins.ceneblock.com
First thing we’ll do is create a non-admin user:
- Manage Jenkins
- Manage Users
- Create User
- Enter the credentials.
Now Jenkins does have the ability to auth off of /etc/shadow or LDAP through:
- Manage Jenkins
- Configure Global Security
Authing off of /etc/shadow is probably not a good idea, but LDAP with Kerberos isn’t that bad; although you’ll want to put some sort of restraint to prevent a script kiddie from getting usernames and passwords.
There are a few ways to set up a Jenkins Project and the absolute easiest is through “Blue Ocean”; however, this is a set of plugins not installed by default.
So as our admin user:
Manage Jenkins
- Manage Plugins
- Avilable
- Search for Blue Ocean
- There will be a lot of options, but you want the one that just says “Blue Ocean”
- Select the Checkbox
- Select “Download Now and Install After Restart”
- At the bottom of the new page, select “Restart Jenkins when installation is complete and no jobs are running”
This will install and restart Jenkins, but if you look at what all is being installed, you’ll notice it supports a lot of Atlassian products… :/
For me, I wound up getting kicked out while it was installing and it seemed liked things were stuck, so after refreshing and logging in as an admin, I noticed on the left hand side there was a Blue Ocean icon.
Clicking on “Open Blue Ocean” I was brought to a page to create my first pipeline.
For the sake of simplicity, we’ll use an old repo that builds a simple webserver that I wrote a few years back.
- Select Github
- It’ll ask you for an auth token. Click the link to generate one (I named mine Jenkins)
- Paste it
- Select what organization this is for (aka your user name).
- You’ll then be presented with all of your repos. For my sake, I’m going to choose an old webserver I wrote a few years back.
- Feel free to fork it if you’re going to follow along (https://github.com/ceneblock/launch_code)
- Select Create Pipeline
It’ll take you to the pipeline editor.
It’s very basic and the first thing you’ll do is click on the “+” icon in the middle of the page.
You’ll want to name this stage (init, in this case), and then select “Add Step”. Search for “Print Message” and then type in “Hello World” (without quotes).
Select Save.
You’ll then be presented with what is essentially a commit dialogue. Put in an optional message and create an optional branch (I did and named it jenkins), and then select “Save and Run”
With this completed, we can see our “Hello World” message. It’s very simple.
If we go back to the Blue Ocean main page (http://localhost:8080/blue), then we can create some additional steps.
Select the project, then select branches.
Mouse over towards the star and select the pencil icon.
This will bring us back to our pipeline editor.
Let’s change the init stage to something more useful for my particular project.
- Select the init stage
- On the right hand side, select “Print Message”
- Select the three dots at the top and delete the step.
- Select Add Step
- Select “Shell Script”
- Type in “sh ./autogen.sh”
- Select the Back Arrow next to where it says “Shell Script”
- Select Add Step
- Select “Shell Script”
- Type in “./configure”
- Select the Back Arrow (again) next to where it says “Shell Script”
Cool, so now our project will create all the necessiary files and configure itself, but we still haven’t built.
Select the plus icon in the main editor to the right of “init”. We’ll name this stage “build”
We’re going to repeat the same steps that we did by calling a shell script, except this time we’re just going to run “make”.
Like before, go ahead and click “save”, put in your commit message if you want then you can watch the project being built.
That is the basics of Jenkins to get yourself started.
You’ll notice that in your repo, that it’ll automatically create a pull request and state which commits passed and which failed.
As a note, if you are going to fork my repo, then delete the Jenkinsfile from your instance so it isn’t automatically picked up when you import the repo and you can go through the steps yourself.
I’ll try to remember to do an update so when I do a push it’ll kick off a new build, but this is enough to get you started.