Archive for the ‘Jenkins’ Category

In last post we configured Jenkins nodes.Now we’ll define nodes on which Jenkins nods will be executed.

It’s simple to do:

First label a  node and in Usage,from drop-down method choose “Only build jobs with label expressions matching this node”



Then on job properties,under General select “Restrict where this project can be run”

and under Label expression Enter node label




Configuring Jenkins Nodes

Posted: September 15, 2018 in Jenkins

Jenkins Slave Nodes are small Java “Client” processes that connect back to a “Master” Jenkins instance over the Java Network Launch Protocol (JNLP).

Task can be executed on Nodes from Jenkins Master

In this example we’ll install Jenkins master and node.

Installing Jenkins Master on CentOS 7

rpm --import
Now we will add the package repository address to our repository list with the command below:
wget -O /etc/yum.repos.d/jenkins.repo
Update your package manager list to get the latest packages:

yum repolist
Finally, install Jenkins and JAVA with the following command:

yum install java-1.8.0-openjdk jenkins
Starting Jenkins
Jenkins will work as a service, so you can control it using “systemctl” command. start your Jenkins server with the following command:

systemctl start jenkins
If you want to make it run at startup execute the command below as well:

systemctl enable jenkins

copy code from path below and login to Jenkins


Make sure jenkins user has shell enabled:

cat /etc/passwd
jenkins:x:996:994:Jenkins Automation Server:/var/lib/jenkins:/bin/bash

Log in as jenkins user

sudo -iu jenkins

Create private/public key pair

ssh-keygen -t rsa
-bash-4.2$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
Created directory '/var/lib/jenkins/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/

Connect to slave,create .ssh folder and copy public key which will be used for automatic master connection to slave.

ssh root@slave IP mkdir -p .ssh
cat .ssh/ | ssh root@slaveIP 'cat >> .ssh/authorized_keys'
mkdir ~/bin && cd bin

slave.jar contains information how to connect from slave to master so we need to copy it from master.

Copy slave.jar from master

wget http://slaveIP:8080/jnlpJars/slave.jar

Now on master node click Manage Jenkins


Click Manage Nodes


Click New Node specify name click Permanent Agent


Jenkins executor is a process which allows master to run a build on a node
this number specifies maximun mumber of concurrent builds that jenkins may perform on this agent

Remote directory is a folder where Jenkins will perform all its operations

Launch command:ssh root@slaveIP java -jar /root/bin/slave.jar



On slave check that java is running:

ps aux | grep java
[root@localhost bin]# ps aux | grep java
root 13541 8.0 3.9 2673952 95020 ? Ssl 17:45 0:13 java -jar /root/bin/slave.jar
root 14302 0.0 0.0 112660 972 pts/1 R+ 17:48 0:00 grep --color=auto java

Continuous deployment with Jenkins

Posted: September 9, 2018 in Jenkins

In this example we’ll copy war file from Jenkins project to Tomcat using Jenkins.

Install Tomcat

configure tomcat credentials:edit file conf\tomcat-users.xml

<role rolename=”manager-script”/>
<role rolename=”admin-gui”/>
<user username=”tomcat” password=”tomcat” roles=”manager-script,admin-gui”/>

If tomcat port needs to be changed, edit file conf\server.xml

<Connector port=”8081″ protocol=”HTTP/1.1″
redirectPort=”8443″ />

Install copy artifact and deploy to container plugins:

Manage Jenkins-Manage Plugins








Create Jenkins job for compiling war file and to invoke other job for copying war files to tommcat (job name:packer)



In build step add Invoke top-level Maven targets

select Maven Version and Goals:clean package


In Post-build Action add Archive the artifacts

Files to archive **/*.war (archive all war file)

Add Post-build Action to run other job after this one is executed (deploy_staging)



Creating job for copying war file to tomcat (deploy_staging)

Build action:pecify project name (one we created in previous step)

Artifacts to copy:**/*.war


Post-build Actions:

Deploy war/ear to a container:**/*.war

Specify tomcat credentials-click Add to add credentials and Tomcat URL






Now run first job (packer), it should compile war file and copy it to Tomcat dierctory



Check Code quality with Jenkins

Posted: September 8, 2018 in Jenkins

With Jenkins Checkstyle plugin generates the trend report for Checkstyle, an open source static code analysis program.

Install plugin by going to Manage Jenkins-Manage plugins-click on Available-in filter type checkstyle and click on Checkstyle checkbox to install plugin.




Once plug-in is installed click on project-Configure


Under Build-Goals add checkstyle:checkstyle at the end of goal line



In Post-build Actions add Publish Checkstyle analsyis results

Your pom file have to be configured to user this checkstyle report


Build the project




If there are any errors/varnings, it will be shown and categorized



Polling source code in Jenkins

Posted: September 5, 2018 in Jenkins

This option will enable Jenkins to monitor GitHub repository and as soon as some changes are committed on GitHub, Jenkins will initiate project build for project.

Under project click Configure


Under Source Code Management click Git-paste Git Repo URL




Under Build Triggers click Poll SCM and specify time interval for checking GitHub repository for changes


Schedule uses crontab format


Click on Git Polling log to see changes


In case i changed something in code, project build will start/



Configuring Jenkins for Git,Maven,Java

Posted: September 4, 2018 in Jenkins

In Jenkins dashboard click Global Tool configuration


If  not already, install JAVA

Set JAVA SDK path






and Maven (installed in last post)


Installing Maven on Windows

Posted: September 4, 2018 in Jenkins

Maven is  tool that can be used for building and managing any Java-based project.

Go to download page and download zip archive to some folder.


In environment variables,under system variables click new for value name set M2_HOME for Variable value path where maven zip file is located


Do the same for JAVA


Under User variables click path-edit and type %M2_HOME%\bin


again, same for java


open CMD and type mvn -v

you should see something as in picture below