Jenkins | Getting started

Inhaltsverzeichnis

Introduction

What is Jenkins. From the Jenkins Homepage, you will get this:

The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

As an extensible automation server, Jenkins can be used as a simple CI server or turned into the continuous delivery hub for any project.

This blog will describe, how to setup jenkins and build an environment where we can build and test a simple python app: a calculator.

Setup Jenkins

Jenkins is a java application. So, to run jenkins, we need to things:

  • a java development kit
  • a jenkins war file

Following the requiements rom the jenkins home page, we should use java8 to run jenkins.

To check your java version, open a console an run

java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.242-b08, mixed mode)

If you need to install the right java version, get it from here.

Download WAR

Next, we need Jenkins. Download the Jenkins here. We will use the weekly generic java package (.war)

wget http://mirrors.jenkins.io/war/latest/jenkins.war

Create Project Home

We want to keep jenkins and all related files and services in one place.

So, lets create the folder jenkins whereever you want.

First create main folder (we will rever to this as JENKINS_ROOT)

mkdir /home/jenkins

Next, we create the folder JENKINS_HOME. This will the the home directory for the jenkins serice.

mkdir /users/jenkins/home

Remember this folders

export JENKINS_ROOT=/home/jenkins
export JENKINS_OME=$JENKINS_ROOT/home

Start Jenkins

java -jar jenkins.war –enable-future-java

Starting Jenkins this way, you will see all log messages on the console.

At this step, the importen messages are the initial admin password:

2020-02-28 16:50:00.749+0000 [id=32]	INFO	jenkins.install.SetupWizard#init:

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

6c408145cc964f72ab45cd80e247fa2d

This may also be found at: /home/jenkins/home(secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2020-02-28 16:50:05.848+0000 [id=57]	INFO	h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller

Start browser and install plugins, create user

$ chrome localhost://8080

Shell access to Jenkins docker

$ docker exec -it jenkins-tutorials bash

Create a Pipeline for a simple Maven Project

Clone the sample maven app

git clone https://github.com/jenkins-docs/simple-java-maven-app

If you want to create a new maven app, you could start with the following command

mvn archetype:generate
        -DgroupId=com.jcg.maven 
        -DartifactId=HelloWorld 
        -DarchetypeArtifactId=maven-archetype-quickstart 
        -DinteractiveMode=false

cd HelloWorld

Install and Build package

mvm clean install

mvn package

Run your app

java -cp target/MavenHelloWorldProject-1.0-SNAPSHOT.jar  com.jcg.maven.App

Troubleshooting

No such DSL method ‘withMaven’ found among steps

This means you don’t have withMaven as an available DSL method. Most of the time this means you don’t have a plugin installed. In this case, the Pipeline Maven Plugin is required. https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin

Links

Local Continuous Delivery Environment With Docker and Jenkins

Additional Readings

Using Oracle Java or OpenJDK.

Install Java on Mac OS with Homebrew

$ brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk8

Install Jenkins with Homebrew on Mac OS

brew install jenkins-lts
brew services start jenkins-lts

Install Jenkins with Docker

$ docker run --rm -u root -p 8080:8080  -p 50000:50000 
  -v jenkins-data:/var/jenkins_home 
  -v /var/run/docker.sock:/var/run/docker.sock 
  -v "$HOME":/home 
  jenkinsci/blueocean