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”

1.PNG

 

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

and under Label expression Enter node label

 

2.PNG

Advertisements

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 https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Now we will add the package repository address to our repository list with the command below:
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/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

1.PNG

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/id_rsa.pub

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/id_rsa.pub | 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

2.png

Click Manage Nodes

3.png

Click New Node specify name click Permanent Agent

4.PNG

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

5.PNG

6.PNG

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”/>
</tomcat-users>

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

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

Install copy artifact and deploy to container plugins:

Manage Jenkins-Manage Plugins

 

7.png

 

 

8.PNG

 

9.PNG

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

 

1.PNG

In build step add Invoke top-level Maven targets

select Maven Version and Goals:clean package

2.PNG

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)

3.PNG

 

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

4.PNG

Post-build Actions:

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

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

 

5.png

 

6.PNG

 

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

 

10.PNG

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.

1.PNG

 

2.PNG

Once plug-in is installed click on project-Configure

3.png

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

 

2-1.PNG

In Post-build Actions add Publish Checkstyle analsyis results

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

Capture.PNG

Build the project

4.png

 

 

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

 

5.png

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

Capture.PNG

Under Source Code Management click Git-paste Git Repo URL

 

6.PNG

 

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

2.PNG

Schedule uses crontab format

3.PNG

Click on Git Polling log to see changes

4.png

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

5.PNG

7.PNG

Configuring Jenkins for Git,Maven,Java

Posted: September 4, 2018 in Jenkins

In Jenkins dashboard click Global Tool configuration

1.png

If  not already, install JAVA

Set JAVA SDK path

 

Capture.PNG

Git-https://git-scm.com/downloads

 

1.PNG

and Maven (installed in last post)

4

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.

1.png

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

2.PNG

Do the same for JAVA

Capture.PNG

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

3.PNG

again, same for java

5.PNG

open CMD and type mvn -v

you should see something as in picture below

6.PNG