Jenkins
Automation Software Allows to Build, Test and Deploy Softwares
Automation Software Allows to Build, Test and Deploy Softwares
It is also called as CI-CD (Continues Integration - Continues Deployment)
Once the developer put the code in Github, Jenkins Pull that code and send to Maven for Build
After the build process Jenkins pull that build code and send to selenium for testing
Once the testing is completed, jenkins pull that code and send to artifactory as per requirement, otherwise, jenkins can deploy
Jenkins also act like a cronjob
Accessing Jenkins only via web
Jenkins need to be installed in Master only
Install Jenkins in Windows
Install Git - https://git-scm.com/download/win
Install Java - https://www.oracle.com/java/technologies/downloads/#license-lightbox
Add Java env variables - in windows search > Edit System Environment Variable > Select Environment Variable > New > Add Variable name(JAVA_HOME) and Value(Java install directory JDK location) > OK
get the Java binary file location > got to Edit System Environment Variable > Path > New > paste bin folder directory location
got to cmd > echo %JAVA_HOME%
Install Maven- https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.zip
move the zip file to c:/devtools > and extract the zip file here >
Now set Envirnmonet Variable > System Variable > New > Variable Name: M2_HOME, Variable Value: Maven DIrectory location
> System Variable > Path > New > Paste maven bin diretory > OK
at CMD > mvn -version
Install Jenkins: https://get.jenkins.io/windows-stable/2.361.1/jenkins.msi
http://ip:8080 - TO access Jenkins web interface
To COnnect Java, Maven , Git etc with Jenkins
Manage Jenkins > Global Tool Configuration > JDK > Add Jadk > unselect auto install > Paste the Jave home directory
> git > automatically execute git exe
> Maven > AddMaven > unselect auto install > Paste the Maven home directory
Manual Build with Maven (Night Build) via CMD
cd /projectfolder/
mvn clean package
"it resulted creating a war file at the location /projectfolder/web/target/project .war"
Build Project with maven via Jenkins
Login to Jenkins > New Items > Enter Item Name > Select "Maven Project" > OK > Any description > Scroll down > Source code Management > GIT > Paste gir repository URL > Build > Goals andOptions = clean package > APPLY > SAVE
"War file location can be found at the log"
If there is any error in the code, the build process show errors
Scheduled Projects
Build Periodically
Every minutes or Every Hours we needs to run build process (CronJob)
Jenkins > click on the project > Configure > Build Triggers > Build Periodically > Paste the time values in corn pattern
Poll SCM
It periodically check for any changes/new commits were made and shall build the project if any new commits were pushed since the last build,
Jenkins > click on the project > Configure > Build Triggers >Poll SCM > * * * * * > Apply > Save
Linked/Related Projects
Upstream Job
An upstream project is one in which a job is triggered before the actual project is triggered. (We can link a job with another one to executing a Build )
Jenkins > click on the project > Configure > Post-build actions > Buildother projects > Paste the Project name > Apply > Save
Down stream Job
Downstream project is one in which a job is triggered after the project has been triggered.
Jenkins > click on the project > Configure > Build Triggers > Build after other jobs are build > Paste the Job name > Apply > Save
Jenkins User Administrator
Jenkins > Manage Jenkins> Manage Users > Create/Delete/Modify
We need to install role plugin toassign various rolss for jenkins users
Jenkins > Manage Jenkins > Manage Plugins > "role" > ROll based authorization > Install
Jenkins > Manage Jenkins > Configure global security > Authorization=Rol Based
Create a roll:
Jenkins > Manage Jenkins > Manage And Assign Rolls > Manage ROles > There we can assign permissions for global roles, Item roles , Developer roles (Patyern= we can give any patterns but project coming with that pattern name only display in the user account"
Install Jenkins in Linux
yum install java-11 java-11-openjdk.x86_64
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins -y
service jenkins start
to unlock jenkins, cat /var/lib/jenkins/secrets/initialAdminPassword
Master and Slave Configuration
That lets you run multiple builds, tests, and product environment across the entire architecture. Jenkins Slaves can be running different build versions of the code for different operating systems and the server Master controls how each of the builds operates.
Manage Jenkins > Manage Nodes and clouds > New Node > Give a Name > Remote root directory = where we want the executed jobs will be like D:/slave1dir > Launch agent via execution of command on the controller (command in help ?) > Now try to build multiple projects it will share the job to different slaves and Master.
We can restrict the project run for a single slave by giving label
Master Slave - External slave
This method establishes a connection from Master to a remote Slave machine and execute projects that we are running from master will be executed on slave.
Install Jave and Jenkins in Master server
Install Jave in Slave server
Access Jenkins web platform
Manage Jenkins > Manage Nodes and clouds > New Node > Paste a slave and Create >
Remote root directory : Create any support /opt/jenkins
Label :any , Custom work dir Path: /opt/jenkins , select Use Websocket > SAVE
Click on the slave, there we can see a code to execute on node to establish connection with Jenkins master. Download the agent.jar file and upload it to slave. FOr eg: /home/ec2-user, chown -R ec2-user:ec2-user /opt/jenkins;
execute that code by adding '&' to keep that command active on backend
Now create a Job > and execute from jenkins > The result and work space will be in slave