Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use jenkins

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "how to use jenkins", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use jenkins" this article.

1. Jenkins introduction

The official website https://jenkins.io

Jenkins is an open source, scalable platform for continuous integration, delivery, deployment (software / code compilation, packaging, deployment) based on the web interface.

Characteristics of jenkins:

Continuous integration and continuous delivery

As an extensible automation server, Jenkins can be used as a simple CI server or as a continuous delivery center for any project.

Easy installation

Jenkins is a stand-alone Java-based program that can be run immediately, including Windows,Mac OS X and other Unix-like operating systems.

Simple configuration

Jenkins can be easily set up and configured through its web interface, including instant error checking and built-in help.

Plug-in

By updating more than 1000 plug-ins in the center, Jenkins integrates almost all of the tools in the continuous integration and continuous delivery tool chain.

Expansion

Jenkins can be extended through its plug-in architecture, providing almost unlimited possibilities for what Jenkins can do.

Distributed system

Jenkins can easily distribute work across multiple machines, helping to drive build, test, and deployment more quickly across multiple platforms.

2. Jenkins installation

Jenkins typically runs as a stand-alone application in its own process, with a built-in Java servlet container / application server (Jetty).

Before installing jenkins, you need to make sure that more than java8 is installed (either the Java runtime environment JRE or the Java development kit JDK)

[root@jin-10 ~] # yum install-y java-1.8.0-openjdk

Download the yum source for jenkins:

[root@jin-10 ~] # wget-O / etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo

Key to install jenkins:

[root@jin-10 ~] # rpm-- import https://pkg.jenkins.io/redhat/jenkins.io.key

Install jenkins:

[root@jin-10 ~] # yum install-y jenkins

Start jenkins:

[root@jin-10 ~] # systemctl start jenkins [root @ jin-10 ~] # ps aux | grep jenkinsjenkins 9180 88.39.9 2336480 99024? Ssl 14:20 0:07 / etc/alternatives/java-Dcom.sun.akuma.Daemon=daemonized-Djava.awt.headless=true-DJENKINS_HOME=/var/lib/jenkins-jar / usr/libjenkins/jenkins.war-- logfile=/var/log/jenkins/jenkins.log-- webroot=/var/cache/jenkins/war-- daemon-- httpPort=8080-- debug=5-- handlerCountMax=100-- handlerCountMaxIdle=20root 9214 0.00.1 112724 996 pts/1 S+ 14:20 grep-- color=auto jenkins

Then open a browser and enter native IP:

The administrator password can be found in the / var/lib/jenkins/secrets/initialAdminPassword file or / var/log/jenkins/jenkins.log in the jenkins log file

After entering the administrator password, click "continue" to enter the plug-in installation interface of jenkins, where we select "install recommended plug-ins":

At this point, jenkins automatically installs the plug-ins that need to be installed:

Then create an administrator account:

Finally, click "start using jenkins":

This brings you to the default interface of jenkins:

Jenkins related directory: [root@jin-10 ~] # rpm-ql jenkins/etc/init.d/jenkins # jenkins on / off / restart file / etc/logrotate.d/jenkins/etc/sysconfig/jenkins # configuration file / usr/lib/jenkins # jenkins home directory / usr/lib/jenkins/jenkins.war/usr/sbin/rcjenkins/var/cache/jenkins # jenkins cache file / var/lib/jenkins # installation directory / var/log/jenkins # log directory jenkins plug-in management

Click the "system Management" → plug-in to manage "→" installed, check whether there are "Git plugin" and "Publish Over SSH" plug-ins, if not, click "optional plug-ins", find it and install it.

Generate a pair of keys on the Linux server:

[root@jin-10 ~] # ssh-keygen-f/root/.ssh/jenkinsGenerating public/private rsa key pair.Created directory'/ root/.ssh'.Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in / root/.ssh/jenkins.Your public key has been saved in / root/.ssh/jenkins.pub.The key fingerprint is:SHA256:fUC8UzU0Q8Ww5zL/zpHVMyMifRzmJ9GA0DoNQocy0Ak root@jin-10The key's randomart image is:+--- [RSA 2048]-+ | E+ O. O.o.o +. = Olympian. | | = Olympus. Oval. | | o. = o +. | | + o + oo. | | S.oroom.roomoplastics + | | .o + * | o. | | .o | |. + | +-- [SHA256]-+

Click the "system Administration" → "system Settings" drop-down to find "Publish Over SSH".

Fill in the following, test whether you can connect, and then click Save:

Add another host to jin-11

Paste the public key contents on jin-10 into .ssh / authorized.keys of jin-11

Then click add:

After the test connection is successful, click Save.

3. Release the code

Click "create a new task" or "New Item":

Add another server jin-11:

Click Save. Then click "Build Now" on the main console:

The build will start automatically, and we can click on the console to view the output:

Then check on the two machines to see if they are successful:

As you can see, both machines executed successfully.

If the code on the github is updated, just click "build now" again on the jenkins to release the update.

4. Configure the mail service built-in mail configuration.

Click "system Management"-> "system Settings"-> "Jenkins Location" to set the email address of the system administrator first. The email address here needs to be the same as the email address to be set later.

Then drop down, find the "E-mail Notification" column to fill in the SMTP server, here we take QQ Mail as an example, SMTP server is smtp.qq.com, and then click Advanced on the right, tick "Use SMTP Authentication", fill in the username password, the password is the authorization code. If you are using the ssl protocol, you also need to check here. The SMTP port defaults to 25 and you can check "Test configuration by sending a test email", and then fill in the address to receive the mail, and click the Test configuration on the right:

As you can see, the mail can be sent successfully.

After saving the settings, go back to the test project and add a post-build operation:

After saving, test:

First delete the files generated by the last build, and then add special permissions to the test_jenkins directory so that files cannot be added to this directory.

[root@jin-10 / tmp] # rm-rf test_jenkins/* [root @ jin-10 / tmp] # chattr + I test_jenkins/

Click build again to view the console:

You can see that the build failed, and at the same time, the mail was sent.

Check to see if you have received the message:

Mail plug-in-Email Extension Plugin

As the built-in mail function is general, can not meet most of the needs, so we generally use the mail plug-in Email Extension Plugin to send mail.

Turn off the built-in email notification, and then click * * system Management * *-> * * system Settings * *-> Extended E-mail Notification. The configuration is as follows:

Then open the test project, delete the original E-mail Notification, and add the post-build operation Editable Email Notification:

Click Save, and then select build now to view the console output:

As you can see, an email is sent regardless of whether the build is successful or not.

5. Deploy JAVA project 5.1 configure maven

The JAVA project needs to be compiled and packaged, which is compiled and packaged using maven, which requires us to install the maven plug-in.

Before installing the maven plug-in, download the maven installation package on the host (jin-10) and extract it:

Download address of maven: https://maven.apache.org/download

[root@jin-10 / usr/local/src] # wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz--2019-09-12 13 root@jin-10 03Murray-http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz is being parsed Host mirror.bit.edu.cn (mirror.bit.edu.cn)... 114.247.56.117, 2001:da8:204:1::22 is connecting mirror.bit.edu.cn (mirror.bit.edu.cn) | 114.247.56.117 |: 80. Connected. A HTTP request has been issued Waiting for a response. 200 OK length: 9142315 (8.7m) [application/octet-stream] is being saved to: "apache-maven-3.6.2-bin.tar.gz" 9142315 344KB/s 28s 2019-09-12 13:27:31 (321 KB/s)-saved "apache-maven-3.6.2-bin.tar.gz" [9142315amp 9142315]) [root@jin-10 / Usr/local/src] # tar zxvf apache-maven-3.6.2-bin.tar.gz

Move the extracted directory to / usr/local/:

[root@jin-10 / usr/local/src] # mv apache-maven-3.6.2 / usr/local/

View information about maven:

[root@jin-10 / usr/local] #. / apache-maven-3.6.2/bin/mvn-- versionApache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117 2019-08-27T23:06:16+08:00) Maven home: / usr/local/apache-maven-3.6.2Java version: 1.8.000222, vendor: Oracle Corporation, runtime: / usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jreDefault locale: zh_CN, platform encoding: UTF-8OS name: "linux", version: "3.10.0-957.27.2.el7.x86_64" Arch: "amd64", family: "unix"

Select system Management-> Global tool configuration-- > add Maven:

5.2 install related plug-ins

System management-> manage plug-ins to see if the Maven Integration and Deploy to container plug-ins have been installed, and if not, install them.

Restart jenkins after the installation is complete

Systemctl restart jenkins5.3 creates a private warehouse

Open gitlab and create a project called test_java and an empty repository:

First, make a global configuration for git to set users and mailboxes:

[root@jin-10] # git config-- global user.name "zjin" [root@jin-10 ~] # git config-- global user.email "zjin@git.com"

Clone the remote repository locally, then write a file README.md and push it to the remote repository:

[root@jin-10] # git clone git@192.168.154.10:root/test_java.git is being cloned to 'test_java'...The authenticity of host' 192.168.154.10 (192.168.154.10) 'can't be established.ECDSA key fingerprint is SHA256:WiJY7DRJy/UJcTtP5LjqnfYrqe9NTP+Rc8Fajy6dzBc.ECDSA key fingerprint is MD5:c3:18:f8:05:ec:89:3f:1b:27:89:61:2b:ec:a7:1e:47.Are you sure you want to continue connecting (yes/no)? YesWarning: Permanently added '192.168.154.10' (ECDSA) to the list of known hosts.warning: you seem to have cloned an empty version library. [root@jin-10 ~] # cd test_java/ [root @ jin-10 ~ / test_java] # README.md [root @ jin-10 ~ / test_java] # git add README.md [root@jin-10 ~ / test_java] # git commit-m "add README.md" [master (root submission) f8d8431] add README.md 1 file changed, 1 insertion (+) create mode 100644 README.md [root @ jin-10 ~ / test_java] # git push-u origin masterCounting objects: 3 Done.Writing objects: 100,221 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0) To git@192.168.154.10:root/test_java.git * [new branch] master-> master branch master is set to track remote branch master from origin. [root@jin-10 ~ / test_java] # echo 'test_java project' > > README.md [root@jin-10 ~ / test_java] # git add README.md [root@jin-10 ~ / test_java] # git commit-m "change README.md" [master 9b9f0bc] change README.md 1 file changed, 1 insertion (+) [root@jin-10 ~ / test_java] # git pushwarning: push.default is not set, and its default value will be changed from' matching' to 'simple' in Git 2.0. To no longer display this information and maintain the current usage habits after its default value is changed, make the following settings: git config-- global push.default matching if you want to stop displaying this information and adopt the new usage habits from now on, set: git config-- global push.default simple see 'git help config' and look for' push.default' for more information. (the 'simple' mode was introduced by Git version 1.7.11. If you sometimes want to use an older version of Git, to maintain compatibility, use 'current' instead of' simple' mode) Counting objects: 5, done.Writing objects: 100% (3 simple' 3), 274 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0) To git@192.168.154.10:root/test_java.git f8d8431..9b9f0bc master-> master

Check to see if the remote warehouse has this file:

Download zrlog source code

Download address: https://codeload.github.com/94fzb/zrlog/zip/master

Decompress after download:

[root@jin-10 ~] # unzip zrlog-master.zip

After decompression, move it to the test_java directory, and then push it to the remote warehouse:

[root@jin-10 ~] # mv zrlog-master/* test_java/mv: do you want to overwrite "test_java/README.md"? Y [root @ jin-10 ~] # root! $cd test_java/ [root @ jin-10 ~ / test_java] # lsbin data LICENSE mvnw.cmd README.en-us.md servicecommon doc mvnw pom.xml README.md web [root @ jin-10 ~ / test_java] # git add. [root@jin-10 ~ / test_java] # git commit-m "add zrlog" [root@jin-10 ~ / test_java] # git push

Check to see if the push was successful to the remote warehouse:

5.5 install and configure tomcat

Download and extract:

[root@jin-10 / usr/local/src] # tar zxvf apache-tomcat-8.5.35.tar.gz [root@jin-10 / usr/local/src] # mv apache-tomcat-8.5.35 / usr/local/ tomcat [root @ jin-10 / usr/local/src] # cd! $cd / usr/local/ tomcat [root @ jin-10 / usr/local/tomcat] # lsbin conf lib logs README.md RUNNING .txt webappsBUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work

Modify the file vim / usr/local/tomcat/conf/tomcat-users.xml by adding the following:

After starting tomcat, you will find that port 8080 is occupied. Let's modify the port to 8081:

Then modify the configuration file vim / usr/local/tomcat/webapps/manager/META-INF/context.xml to add the IP section of the following figure:

Restart tomcat again:

[root@jin-10 ~] # / usr/local/tomcat/bin/shutdown.sh Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usrUsing CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar [root@jin-10 ~] # / usr/local/tomcat/ Bin/startup.sh Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usrUsing CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started.[ root @ jin-10 ~] # netstat-lntp | grep 8081tcp6 0 0:: 8081 :: * LISTEN 53513/java

Open it in the browser and click the location shown in the figure, and we will be prompted to enter a user name and password for authentication:

When you click OK, you will enter the Tomcat Web Application Manager management interface:

5.6 build job

Go back to the main interface of jenkins, click New, customize the name, select build a maven project, and click OK.

Source code management, select the gitlab address to be built:

An error will be reported at this time. You need to configure the corresponding key. Click "Add", then select "jenkins", select "SSH Username with private key" for type, enter "git" for username, and then paste the private key of the jin-10 host:

Fill in the "build" column as follows:

"Post-build actions", select "Editable Email Notification" in "add post-build actions", as shown in the figure:

Release war package

Post-build operation

Click "add post-build steps" to select "Deploy war/ear to a container", "WAR/EAR files" to fill in "* * / * .war", Contex path to leave blank, Containers to select Tomcat 8.x Tomcat URL to fill in the url of the machine to which you want to publish the war package, such as http://192.168.154.10:8080 Credentials, you need to click on the Add on the right here to add the user name and password.

Continue to click "add post-build steps" and select "Editable Email Notification" Project Recipient List and change it to $DEFAULT_RECIPIENTS,493734218@ qq.com, which means adding an additional recipient.

Click "Advanced settings" in the lower right corner, locate "Triggers", and then click "Add Trigger" below to increase the conditions for sending email.

Finally, click "Save" in the lower left corner.

You can then click "build now" on the left, and then you can view the console output of the corresponding task.

The above is all the contents of this article "how to use jenkins". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 270

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report