Nerd For Tech
Published in

Nerd For Tech

Jenkins and Jib | Build and upload images to private Docker Repo

Photo by JJ Ying on Unsplash

A few days ago, I needed to create a new Project without any templates from scratch, that should be able to use Micronaut as a serverless Framework. My application is written in Kotlin. In the end, It should work like a webserver, that gets deployed on Kubernetes. First of all, There are three key components. The first one is the Application itself. This application needs to be converted to a docker image. The next part is the Pipeline. It needs to run some automated tests and build the whole image if the tests are successful. It should also push the image to artifactory or any other private docker repo. The last part is the Kubernetes Cluster, that deploys the helm-chart. In this tutorial, I will only look at the first two steps. I will create an article on this topic later.

Create the docker image from the application

First of all, we need to have a tested and running application. The next step is to add the google jib plugin to your plugins.

I also added the nebula release plugin from Netflix for the semantic releasing of these images.

Before you can use the jib plugin in its full potential, you need to configure it.

The first part is the same as in the Dockerfile. You also build it from openjdk:14-alpine, which is an ultra lightweight java image. The second part is for the publishing. It uploads your image to the destination you defined and tags it with the project-version. For private repos, you need to define the auth section with a username and password.

Now you can run the jib command to create the new image.

As you see here, there are two methods to release and build such an image. The first line creates an image with the name in the form of:


The second line uses the final keyword from the nebula plugin. It looks like this.


Where # is the number of release candidates for this version produced so far.

Create your build Pipeline

I created a new Jenkins Pipeline, but you could also use any other Pipeline system. The important part is in the Jenkins file. Let’s take a look at it.

Actually, the most important part of this file is the publish-release stage. It uses credentials for the private docker repo. These credentials need to be defined in Jenkins. Click here if you want to know how to create new credentials in Jenkins. If we take a closer look at these few lines, we can see that we have an if clause, that either creates a devSnapshot when there is no tag on the git commit starting with a “v”, or creates a final release with the last git tag.

In the end, if everything worked, you should now be able to see some images, either devSnapshots or final releases, in your private docker repo. If this is the case,… Congratulations! You just pushed your first images to a docker repo.


What went good?

The building of the docker image worked like a charm. The Google Jib plugin made a pretty good job in creating these images. The images were faster as expected and easy to create.

What needs improvement?

First, I had some problems with the semantic versioning of the docker images. After some time reading in the docs, I found what i was doing wrong. I was missing the -P in front of release.useLastTag . The second problem that I had was, that i forgot to add an authentication clause to the configuration of the Jib plugin. I was wondering why my images couldn’t get pushed to the repo, but it is clear, because it need an authentication.

I hope you could learn something. 😊



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store