Install Jenkins on Linux

Before installation, please make sure you have installed JDK, Tomcat, Maven.

1 Import Jenkins key, install

[root@iZ94zsv4mnfZ ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
[root@iZ94zsv4mnfZ ~]# rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
[root@iZ94zsv4mnfZ ~]# yum install jenkins
Enter y

 

2 Modify the configuration

[root@iZ94zsv4mnfZ ~]# vim /etc/sysconfig/jenkins

Modify the following configuration:

#Avoid insufficient permissions when executing scripts

JENKINS_USER="root"

#The default is 8080, which conflicts with the port of tomcat. Here I am changing it to 8888. If your port 8080 is not occupied, you can leave it unchanged.

JENKINS_PORT="8888"

 

JENKINS_USER I have set root here and need to give access to rootjenkins的权限

[root@iZ94zsv4mnfZ ~]# chown -R root /var/log/jenkins
[root@iZ94zsv4mnfZ ~]# chgrp -R root /var/log/jenkins
[root@iZ94zsv4mnfZ ~]# chown -R root /var/lib/jenkins
[root@iZ94zsv4mnfZ ~]# chgrp -R root /var/lib/jenkins
[root@iZ94zsv4mnfZ ~]# chown -R root /var/cache/jenkins
[root@iZ94zsv4mnfZ ~]# chgrp -R root /var/cache/jenkins

 

Modify another configuration

[root@iZ94zsv4mnfZ ~]# vim /etc/init.d/jenkins

turn up

candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.0/bin/java
/usr/lib/jvm/java- 1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8. 0/bin/java
/usr/bin
/java Add a line above /usr/bin/java: /usr/java/jdk1.8.0_102/bin/java The front is your java installation path.

 

which ends up as follows

candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/java/jdk1.8.0_102/bin/java
/usr/bin/java

 

3 start

[root@iZ94zsv4mnfZ ~]# service jenkins start
After the startup is complete, you can log in to  http:// IP:8888/ to access Jenkins

The first time you log in to Jenkins, you will be asked to unlock

 



 Copy the password input to the specified path.

[root@iZ94zsv4mnfZ ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
957fef857878401497edeed960c01b0d
Enter the above string

 

After the input is completed, you will be prompted to install a custom plug-in or a recommended plug-in. Here we choose the recommended plug-in:

 and then wait for the installation to complete.



 



 

 

 

Install the maven plugin

Go to System Management -> Manage Plug-ins in turn, click on optional plug-ins, search for Maven Integration plugin, check it and click on Direct Install

 

 

4 Configuration environment

Go to System Management -> Global Tool Configuration

 

JDK



 

MAVEN



 

click save

 

Go to System Management -> Management Node



 Click the settings icon



 

5 Create a job

Enter the home page and click New, enter the item name, and click to build a maven project



 

 

Select source code management



 Add svn address, account and password and

 select build



 Post-build actions



Preservation
department script:

#!/bin/bash
#Tomcat root directory
#Note that you need to modify it to your own tomcat path here
TOMCAT_HOME="/usr/local/tomcat7"
#port
#Note that you need to modify this to your own tomcat port
TOMCAT_PORT=8080
#TOMCAT_PID is used to detect if Tomcat is running
TOMCAT_PID=`lsof -n -P -t -i :${TOMCAT_PORT}`

#If Tomcat is still running
if [ -n "${TOMCAT_PID}" ]; then
 #Close Tomcat
#Note here. If tomcat is not registered as a service use the following way
 #${TOMCAT_HOME}/bin/shutdown.sh
 service tomcat7 stop
 #loop to check if Tomcat is closed
 while [ -n "${TOMCAT_PID}" ]
 do
  #wait for 1 second
  sleep 1
  #Get the PID of the running process on port 8080. If the PID is empty, it means that Tomcat has been shut down
  TOMCAT_PID=`lsof -n -P -t -i :${TOMCAT_PORT}`
  echo "Closing Tomcat["${TOMCAT_PORT}"]..."
 done
 echo "Successfully shut down Tomcat."
be

#Note here: zwp-web is my packaged package name
warPath="${TOMCAT_HOME}/webapps/zwp-web/"
warFile="${TOMCAT_HOME}/webapps/zwp-web.war"

#Delete the file or folder if it exists
deleteWhenExist(){
 if [ -e $1 ]; then
  rm -rf $1
 be
}

deleteWhenExist ${warPath}
deleteWhenExist ${warFile}

#Note here: zwp/zwp-web/target/zwp-web.war needs to modify your own corresponding path
#Copy the newly compiled package to Tomcat
cp /var/lib/jenkins/workspace/zwp/zwp-web/target/zwp-web.war ${TOMCAT_HOME}/webapps/

#Note here. If tomcat is not registered as a service use the following way
#${TOMCAT_HOME}/bin/startup.sh
service tomcat7 start
echo "Starting Tomcat["${TOMCAT_PORT}"]..."

#Check whether Tomcat has been started
while [ -z "${TOMCAT_PID}" ]
do
 sleep 1
 #echo "TOMCAT_PID["${TOMCAT_PID}"]"
 TOMCAT_PID=`lsof -n -P -t -i :${TOMCAT_PORT}`
 echo "Starting Tomcat["${TOMCAT_PORT}"]..."
done

echo "Successfully started Tomcat."

 

 

Go to the home page.



 Click on the zwp project

Click Build Now to

 see the console output



 Access our deployed projects

http://ip:8080/zwp-web/



 

 

 

Note: Some paths in the deployment script need to be modified by yourself.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326676911&siteId=291194637