linux jenkins 2.89.1 installation and deployment Continuously build maven projects under svn and deploy to tomcat

You can learn from this blog post:

  1. jenkins installation
  2. Modify home directory
  3. initialization
  4. Create a new task to build the first maven project
  5. Deploy the built project to tomcat

The installation of Jenkins is quite simple. You only need to download the war package from the official website, put it in tomcat, and run tomcat to access Jenkins.

Preparations: Install the java environment, a tomcat7+. If you build a maven project, you also need to install maven

1. Download jenkins.war from the Jenkins official website

wget http://mirrors.jenkins.io/war-stable/2.89.1/jenkins.war

2. Put jenkins.war into tomcat/webapps/

3. Start tomcat

Jenkins installed successfully, go to the browser to visit

ip: port/jenkins port is the tomcat port where Jenkins is deployed

Access will see the following interface, the first time you access Jenkins, you need to unlock Jenkins

The red font on the page is the password path

We open this file and copy the password

Paste into password box

Click continue to continue

Pause. . . .

Modify the jenkins home directory

The default home directory of jenkins is the user directory /.jenkins/

I am using the root account so the default home directory is under /root/.jenkins/

The home directory information of jenkins is also printed from the tomcat startup log

Jenkins home directory: /root/.jenkins found at: $user.home/.jenkins

We do not use the default directory and change the jenkins home directory to our own directory for easy management

Modification method: Edit the webapps/jenkins/WEB-INF/web.xml file

  <!-- if specified, this value is used as the Hudson home directory -->
  <env-entry>
    <env-entry-name>HUDSON_HOME</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value></env-entry-value>
  </env-entry>

Put the specified jenkins home directory into the <env-entry-value></env-entry-value> node

  <!-- if specified, this value is used as the Hudson home directory -->
  <env-entry>
    <env-entry-name>HUDSON_HOME</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>/usr/local/softs/jenkins/home-dev/</env-entry-value>
  </env-entry>

:wq save and exit

Restart tomcat to access jenkins

We can see that the red password path has become a custom directory

The same operation, enter the password

vi /usr/local/softs/jenkins/home-dev/secrets/initialAdminPassword

Next step

This step is to choose to install the plug-in, we choose the left side, install the suggested plug-in

Wait a moment, the plugin is automatically downloading and installing

After the installation is complete, it will automatically create a user interface

You can create a user here, I did not create it, use the default account admin, click Continue as admin  in the lower right corner, click Save and Finish if you create it

ps: If the default admin is used, the user name is admin and the password is the initialization password used to enter jenkins for the first time

Jenkins is initialized, click Start using Jenkins to start using

Change password: Click on the upper right corner to log in the user -> click on the left side -> enter a new password in the password field and confirm the password -> click save to change the new password

Enter the main interface

configure jenkins

Configure the jenkins environment for building the first maven project

1. Configure jdk/maven Click System Management -> Global Tool Configuration

Click to add JDK

Do not check the automatic installation, use the jdk we installed ourselves

Enter JAVA_HOME

maven

Click Add maven, uncheck the automatic installation check

click save

2. Install the plug-in Click System Management -> Manage Plug-ins

Building maven requires 3 plugins

Subversion Plug-in: svn plug-in, installed during initialization

Maven Integration plugin: used to build maven projects

Deploy to container Plugin: Automatically deploy web projects to tomcat after building

Check the plugins you want to install in the optional plugins

Click to install directly

Check Restart Jenkins after installation (when idle) Jenkins will restart automatically after installation is complete

After the installation is successfully restarted, the new task will have

Create a new task to build the first maven project

General

source code management

Select Subversion, enter the url, the warning shows that the library cannot be accessed, click Add to add the svn username and password

Add svn username and password

After adding, Credentials select the account password just added

build trigger

build environment

The build environment is the configuration for maven

Root POM: The location of the pom.xml file, generally in the root directory

Goals and options: execute mvn command

 jenkins also supports personalized operations Pre Steps / Post Steps before and after the build

Pre Steps: Execute before build

Post Steps: Execute after build

 

Pre Steps/Post Steps can execute shell, execute maven commands, etc.

These two are very useful, like shutting down tomcat before building and restarting tomcat after building.  

eg: Let's execute a shell command before and after the build

build settings

Email notification can be set

Post-build action (deploy to tomcat)

After all the above steps are completed, perform the post-build operation, you can deploy the project to the warehouse, delete the workspace directory after the build is complete, and if it is a web project, you can also deploy the war to tomcat

We will deploy the war to tomcat under the specific operation

1. Prepare a complete tomcat

The tomcat webapps/ directory structure downloaded from the official website

After startup, you can access the tomcat home page

2. Modify the tomcat/conf/tomcat-users.xml configuration file

Add a user to the <tomcat-users></tomcat-users> node

<?xml version='1.0' encoding='utf-8'?>

<tomcat-users>
	<role rolename="admin-gui"></role>
	<role rolename="admin-script"></role>
	<role rolename="manager-gui"></role>
	<role rolename="manager-script"></role>
	<role rolename="manager-jmx"></role>
	<role rolename="manager-status"></role>
	<!-- username:用户名 因为我svn的用户名是admin,为了好区分,我这里将用户名设置为tomcat-admin   password:密码 -->
	<user username="tomcat-admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
<tomcat-users>

After modification, restart tomcat, we visit the tomcat home page to test the username and password, click Manager App to enter the tomcat UI management interface, click Manager App will prompt to log in, enter the username/password we just set to log in

If the login is successful, the username and password are available.

3. Add the steps to build enough operations, select Deploy war/ear to a container

WAR/EAR files: war path, in the project target directory, the file path is in solr-home/workspace/project/target/xxx.war

Context path: the name of the project deployed to tomcat/werapps/

Set up, start building

Click Save and you will see a project named maven-web on the home page

Click the button on the far right to build

The build is successful, let's go to tomcat/webapps to see

The war has been deployed to webapps and the name of the war package has been changed to the set maven-web.war

Enter ip: port/maven-web/index.jsp access is successful

In the console output of jenkins, you can see that the scripts before and after the build are also executed before and after the build.

 

The installation and deployment of jenkins, building the first maven project, and deploying the built project to tomcat have all been completed, good luck

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324374468&siteId=291194637