Jenkins in a Linux Container (Part 2)

This is the second and last part of running Jenkins in a Linux Container. It started with the thought to use Linux containers, and why not for a real use case of running Jenkins in the container. If you have missed the first part you can click on the link.

We left of were Jenkins was running in the container, we will start up the container and access Jenkins’s web page to configure the system. The aim is to build a simple C project that is compiled and executed by Jenkins. For starting up the container you can use the following commands in your terminal:

With the attach command you will get terminal access to the Linux Container. In order to build the the C project you will need make, gcc tool-chain and git, therefore you need to run the following in the Container:

Use ifconfig to find out the IP address of the Linux Container.

Now go back to your host system to run a web browser and use the IP address you found, including the port number 8080, in my case

Unlock Jenkins

Unlock Jenkins

It will ask to Unlock Jenkins, go to the terminal of the Linux Container and cat the password:

Copy the password into your web-browser and click continue. For easy and straightforward installation let Jenkins install the suggested plugins, you can always change them afterwards if necessary:

Install Suggested Plugins

Install Suggested Plugins

After installing the plugins you need to create your first admin user. Fill out the credentials and Click “Save and Finish” followed by Start using Jenkins. Because we want to create a scheduled build project based on a simple Makefile project that is coming from GitHub, click on “New item” on the left. Fill out the project name, e.g. “EmbedWise-example_project_makefile” and select “Freestyle project” and click OK.

New Freestyle project

New Freestyle project

Select the option GitHub project and supply the URL

Select Github project

Select GitHub project

Scroll down to Source Code Management segment and select Git with the URL note that this URL has the extension .git at the end:

Set Source Code Management to Git with no Credentials

Set Source Code Management to Git with no credentials

It is not necessary to supply any credentials since it will only retrieve (Read only) the project from Git. As Build trigger we select Build periodically with the schedule H/15 * * * *, which means that it will build every 15 minutes, for more info you can click the “?” icon at the right side.

Build trigger set to build periodically

Build trigger set to build periodically

This periodically build trigger can also be used for nightly builds. Another possibility was to select “Build when a change is pushed to GitHub”, it will then only build if something changes, this can be a nice trigger for Unit testing. But for now we will use the periodically build trigger.

At the end we have to tell Jenkins how to build the project. In this case we use a Makefile, which is called by a Bash script Calling a script is a good convention in Jenkins, because then the script is also under source control and it keeps the setup in Jenkins clean and straightforward:

Add build step to execute shell script

Add build step to execute shell script

Click Save, to save this project. In the main window of Jenkins you will now see your new project:

Overview of projects in Jenkins

Overview of projects in Jenkins

By clicking on the project, you will see the project specific overview were you can also manually start the fetch from Git process and build the project, by clicking on “Build Now”:

Build now

When the build has finished, you can see that in the “Build History” on the left. You can click on the build number in my case “#19”, this will show the Build information of a specific run:

Build information

By looking at the “Console Output” we can see the build process. At the end of the build the binary example is executed, which is a C program that prints “This is an example program…” to the screen. This shows that the complete setup of Jenkins including the C project is working.

Console output

As you can see Jenkins is easy to use, there are numerous ways to setup a project and extend it with all kind of testing, scripting and conducting (code) analysis. It is a very strong and versatile automating tool. The steps taken showed how to get up and running with a project in Jenkins running in a Linux Container. Good to know is that Jenkins 2.0 is now officially released, this was not the case when the first part of the post was published. Hope you got inspired like myself and start experimenting on your own.

Leave a Reply

Your email address will not be published. Required fields are marked *