Jenkins automated deployment

Example: In the Linux environment, the installed jenkins, integrated svn, the project is the maven project Jenkins configuration

On the Jenkins homepage, click on Manage Jenkins, then click Manage Plugins to manage the necessary plugins, svn, maven, ssh, etc.

Jenkins automated deployment

Then Jenkins home page, click Manage Jenkins, then click Global Tool Configuration tool configuration, configure JDK, Maven, etc.

Jenkins automated deployment

Jenkins automated deployment

Jenkins use

The first step: create a new task on the home page, then fill in the task name, select the free style project

Jenkins automated deployment
Jenkins automated deployment

The second step, the project name, can be modified

Jenkins automated deployment

Step 3: Add the svn address and set it, username and password

Step 4: When building, there are three situations

Case 1, using maven for project construction, using plugin release

Jenkins automated deployment

The fourth step: When constructing, there are two situations. It is recommended to use a third party.

Case 1, using maven for project construction, using plugin release

Jenkins automated deployment

Post-build operation, use the plug-in to publish the project, publish the project, the plug-in required for the project release is (Deploy to container Plugin), publish to tomcat, need to use the tomcat username and password, tomcat users can themselves in tomcat Configured in conf/tomcat-users.xml file

Jenkins automated deployment

Tomcat-users.xml configuration

Jenkins automated deployment

Case 2, use the shell command to build the project, and then directly use the command to publish. When executing tomcat startup, you need to add the command export BUILD_ID=dontKillMe

Jenkins automated deployment

Jenkins build output

Jenkins automated deployment

Case 3, use the shell command to build the project, and then directly use the command to publish. When executing tomcat startup, you need to add the command export BUILD_ID=dontKillMe

Jenkins automated deployment

Script source code:

Export BUILD_ID=dontKillMe

Rm -rf /alidata/ejoined/server/apache-tomcat-8365/webapps/ROOT

Cp -R /var/lib/jenkins/workspace/adsl-taobao-admin/target/ROOT.war /alidata/ejoined/server/apache-tomcat-8365/webapps/

Tomcatpath=“/alidata/ejoined/server/apache-tomcat-8365”

Pid=$(ps -ef | grep java | grep ${tomcatpath} | awk '{print $2}')

Kill -9 $pid

Rm -rf ${tomcatpath}/work/Catalina/localhost/*

Sleep 1

${tomcatpath}/bin/startup.sh

Completed above;

But there will be some anomalies; as follows:

Jenkins automated deployment

As shown in the figure above: the compilation is successful, but no matter how the script is executed, there is no permission (Permission denied).

I have finally gotten the time for such a problem. How to solve that?

Start below, from the analysis of the problem, it can be seen that the current user name used by the current Jenkins user on the host Linux server is incorrect.

That's the problem,

Let's start by explaining the solution steps:

1. First check where you want to use the script to run the script, the target file or directory pointed to by the script in case three in this article is (/alidata/ejoined/server/apache-tomcat-8365), all the things under this file, Look at the executable user on the directory pointed to, as shown below:

Jenkins automated deployment

As you can see from the figure, the executable user is root.

The target file or directory pointed to by the script must have executable permissions;

Modify permission command: chmod -R 755 target directory name

2. Know the directory pointed to by the script or the user pointed to by the file, then the next step is solved.

How to modify the Linux account running the jenkins process?

1, find the configuration file of jenkins, usually /etc/sysconfig/jenkins

2. Modify the following parameters to the corresponding user, such as JENKINS_USER=“root”

## Type: string

## Default: "jenkins"

## ServiceRestart: jenkins

#

# Unix user account that runs the Jenkins daemon

# Be careful when you change this, as you need to update

# permissions of $JENKINS_HOME and /var/log/jenkins.

#

JENKINS_USER=“jenkins”

3, restart jenkins: service jenkins restart

Open the browser to enter the address, start again from the compilation of the first project, and then you will find success.

Ego E cigarette

Suizhou simi intelligent technology development co., LTD , https://www.msmvape.com