Jenkins installation configuration and plug-in installation and use

Personal understanding of continuous integration: In order to solve the low quality of program code submission and the bugs of the original system caused by the submitted content, the version is automatically compiled on time or on demand, and automated testing is performed.

Baidu's definition of continuous integration: continuous integration is a software development practice, that is, team development members often integrate their work, usually each member integrates at least once a day, which means that integration may occur multiple times a day. Each integration is verified through automated construction (including compilation, release, and automated testing), so that integration errors can be found as soon as possible. Many teams have found that this process greatly reduces integration problems, allowing the team to develop cohesive software more quickly.

Why I wrote this article: The author encountered a lot of pitfalls in the process of learning jenkins, and a lot of information found during the learning process was too scattered, resulting in slow learning progress. I want to use this article to let everyone in the learning process. Take a detour. Although I don't expect this article to be possible, it is also good to help a few people. In this hope, everyone encourages each other.

1. Jenkins installation

System & Installation

Use the WAR file directly

Installation package installation

Put the WAR file into the WEB container

Windows system

Difficulty: Low

Difficulty: Medium

Difficulty: high

Linux system

Difficulty: Low

Difficulty: Medium

Difficulty: high

Mac system

Difficulty: Low

Difficulty: Medium

Difficulty: high

The author recommends using WAR files directly, the simpler things are more suitable for beginners. And the author used the installation package to install, and there was a situation where the list of plug-ins could not be obtained once.

   

Install under Windows:

system version

JDK version

Jenkins version

Windows10

JDK8

Jenkins1.651

 

  1. Install JDK: (Installation of jdk under windows and configuration of environment variables on Baidu)
  2. Download and install the latest version of Jenkins:
    log in to http://jenkins-ci.org/ to download the windows version.
    The downloaded compressed package contains a .msi program, which can be installed directly

  1. Access Jenkins: Direct access to Jenkins http://local IP: 8080 (8080 is the default port number of jenkins)

 

Install under Linux Ubuntu:

system version

JDK version

Jenkins version

Ubuntu 14.04LTS Desktop Edition

Openjdk-7-jdk

Jenkins1.651

Ubuntu installation package installation:

  1. Install open-JDK:

    sudo apt-get install openjdk-7-jdk

  2. Install Jenkins:

    wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -sudo sh -c 'echo deb Debian Jenkins Packages binary/ > /etc/apt/sources.list.d/jenkins.list'
    sudo apt-get update -y
    sudo apt-get install jenkins -y

  3. Installation location:

    Installation directory: /var/lib/jenkins
    Log directory: /var/log/jenkins/jenkins.log

  4. Start stop service:

    sudo /etc/init.d/jenkins start
    sudo /etc/init.d/jenkins stop

  5. Access jenkins:

    http:// local IP:8080/

Using the WAR file directly:

  1. Install open-JDK (same as above)
  2. download war file

 

Import the corresponding war file to the Linux server (the following briefly introduces several importing methods, just to provide ideas for Baidu and Google)

  • Set up FTP server
  • Winscp tool incoming
  • The virtual machine can be dragged into or started the shared folder with the virtual machine enhancement tool
  • U disk and other hardware access
  • Start the service using the war file

Java -jar /home/jenkins.war (wan file path) --Port=8080 (port)

  1. access jenkins

    http:// local IP:8080/

  2. Add the service to boot

    cd /etc/init.d //switch directory
    vi jenkins.sh //write shell script
    and insert java -jar /home/jenkins.war(wan file path) --Port=8080(port)& //run
    chmod 755 in the background jenkins.sh //Modify shell script permissions
    update-rc.d test defaults 95 (start sequence number) //Add startup items
    update-rc.d -f jenkins.sh remove //Delete startup items (need to be in /etc/init Execute under the .d directory)

  3. Jenkins installation directory:

    /root/.jenkins/

  4. Access jenkins:

    http:// local IP:8080/jenkins/

TomCat+Jenkins:

  1. Download and install jdk (same as above)
  2. Download the WAR file (same as above)
  3. Download and install tomcat

 

  1. download tomcat

    http://tomcat.apache.org/download-80.cgi 

  2. Pass the tomcat installation package to the server
  3. Unzip the installation package

    tar -cvzf apache-tomcat-8.0.12.tar.gz

  4. Copy the decompressed file to your desired installation path

    cp -r apache-tomcat-8.0.12/destination path

  5. Enter the installation path, take /opt/tomcat/ as an example

    cd /opt/tomcat/

  6. Edit the tomcat startup script and add environment variables

    vim ./bin/startup.sh

    Add some content, change the path to your own environment variable path

    JAVA_HOME=/usr/lib/jvm/jdk1.8.0_31

    JRE_HOME=${JAVA_HOME}/jre

    PATH=$JAVA_HOME/bin:$PATH

    CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

    TOMCAT_HOME=/opt/apache-tomcat-8.0.17

    ps: It needs to be placed above the exec "$PRGDIR"/"$EXECUTABLE" start "$@" line

  7. Edit the catalina.sh file and add environment variables, otherwise jenkins will report that Ant cannot be found

    #See the license for the……

    JAVA_HOME=/usr/lib/jvm/jdk1.8.0_31

    Export JENKINS_HOME="/root/.jenkins" 

  1. Put the WAR file into the tomcat installation path/webapps/directory
  2. Start & shut down tomcat

  3.  ./bin/startup.sh

    ./bin/shutdown.sh

  4. Jenkins installation directory:

    /root/.jenkins/

2. Introduction to Jenkins configuration and plug-in installation and use
   

The HTML Publisher Plugin plug-in in the new Jenkins version will cause CSS to be unable to be loaded and buttons to be clicked on the opened webpage. Due to CSP, it can be executed in the Jenkins console: System.setProperty("hudson.model.DirectoryBrowserSupport.CSP" , "") to fix this. Other html plug-ins caused by CSP can also be solved by this method.

 

   

Plugin installation:

installation method

Install online

install after download

Strengths and weaknesses

Advantage: Automatically install dependencies

Cons: Slow to install

Advantage: fast

Defect: does not automatically install dependencies

 

Online installation:

   

  1. Enter system management

  2. Enter plugin management

  1. Toggle Optional Plugins Tab

  2. Select the plug-in and install it directly

 

If the optional plugin is empty

  • switch to advanced interface

  • Click the Get Now button

 

  • If an error is reported, it is recommended to reinstall jenkins directly (check the solution for a day, give up, and reinstall it directly)

Offline installation:

   

  1. Enter plugin management, advanced page

 

upload plugin

It will be installed automatically after uploading successfully

If the installation fails, please go to the corresponding plug-in page to check whether the corresponding dependencies are installed

 

Account security configuration:

   

PS:
If the user permission configuration is incorrect and cannot be modified, modify the config.xml file in the jenkins installation directory of the server and restart the jenkins service.

Enter system management—Configure Global Security

 

  1. Select the Jenkins dedicated user database, allow users to register, save

  2. registered user

  1. Enter Configure Global Security again
  2. Start the security matrix, add users, add permissions, save

 

3. Jenkins environment variable description

  • List of environment variables:

  • - BUILD_NUMBER, uniquely identifies a build, such as 23;
    - BUILD_ID, basically equal to BUILD_NUMBER, but it is a string, such as 2011-11-15_16-06-21; currently only ID
    - JOB_NAME, the name of the job, such as JavaoWorld;
    - BUILD_TAG, same as BUILD_ID, BUILD_NUMBER, used to globally uniquely identify a build, such as jenkins-JavaHelloWorld-23; -
    EXECUTOR_NUMBER, such as 0;
    - NODE_NAME, the name of the slave, such as MyServer01;
    - NODE_LABELS, the label of the slave, identifies the slave Useful, such as JavaHelloWorldMyServer01;
    - JAVA_HOME, the home directory of java, such as C:\Program Files (x86)\Java\jdk1.7.0_01;
    - WORKSPACE, the current working directory of the job, such as c:\jenkins\workspace\JavaHelloWorld;
    - HUDSON_URL = JENKINS_URL, the url of jenkins, such as http://localhost:8000/;
    - BUILD_URL, the url of build, such as http://localhost:8000/job/JavaHelloWorld/23/;
    - JOB_URL, the url of the job, such as http ://localhost:8000/job/JavaHelloWorld/;
    - SVN_REVISION, revision of svn, for example 4;

  • Special attention should be paid to system management, system settings, and references to 3 variables in advanced (especially after reinstalling jenkins, you must check whether it is consistent with the previous Jenkins, even if it is the same version or even the same WAR file)

4. Use of Jenkins

  1. Create a project, enter a project name, select a project type

 

  1. Enter project information according to the project situation

  2. Construct

  1. View the build results (the blue dot is success, the red dot is failure, and the Console Output option is to view the build log)

Five, build

  • build trigger

 

  • Trigger remote builds (script builds)
  • Build after other projects are built (build this project after other builds are complete)
  • Build periodically
  • Poll SCM (check codebase)

build script

   

 

    • Execute Windows batch command: Add Dos script build step
    • Execute shell: add shell build step
    • Invoke Ant: Add Ant build step
    • Invoke top—level Maven targets: Add a Marven build step
  • post-build operations

  • E-mail Notification adds sending mail configuration
  • Publish Html report (HTML Publisher plugin), add view Html result configuration (absolute path, relative path starts with workspace)

6. Precautions for cross-platform use of Jenkins

  • path:

Jenkins path format:
Windows server also supports "/" and "\" coexistence mode, and "/" is recommended for cross-platform use.
PS: It is possible to read the information, but I have not tried it

Guess you like

Origin blog.csdn.net/okcross0/article/details/132715416