Jenkins installation and configuration-centos6.9, jenkins-centos6.9

Source: Internet
Author: User
Tags lost password

Jenkins installation and configuration-centos6.9, jenkins-centos6.9

Install and configure Jenkins

Directory

1. install java. 2

1.1 installation instructions... 2

1.2 create a java directory... 2

1.3 download and decompress... 2

1.4 set the environment variable... 2

1.5 verify JDK validity... 3

2. Install Git. 3

2.1 install the GCC software package... 3

2.2 download and install Git. 4

3. Install jenkins. 5

3.1 download and install... 5

3.2 start Jenkins. 5

3.3 Set firewall... 6

3.4 error solution... 7

4. Quickly configure Jenkins. 8

4.1 Basic settings... 8

4.2 install plug-ins... 10

4.3 set the plug-in... 11

4.4 configure email... 12

5. Create and configure a project... 16

5.1 create a project and configure the Git library... 16

5.2 set building trigger... 18

5.3 build step settings... 20

5.4 add post-build operations... 21

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1. Install java1.1

This description is based on the server version: Virtual Machine CentOs 6.9 memory 4 GB

Java: 1.8

Jenkins version: 2.103

GItlab: 10.1

Pay attention to the java version (1.8 or above is recommended)

We recommend that you install vim: yum-y install vim-enhanced.

 

Jenkins is a Continuous integration CI (Continuous integration) system designed to monitor the software development process and quickly display problems. Reduce repetitive processes and improve work efficiency.

1.2 create a java directory

[Root @ localhost ~] # Mkdir/usr/java

[Root @ localhost ~] # Cd/usr/java

 

1.3 download and decompress

You can download the file locally and then upload it to the server,

Http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/jdk-8u162-linux-x64.tar.gz

-- Use the WinSCP tool to upload it to/usr/java and decompress the package.

 

[Root @ localhost java] # tar-zxvf jdk-8u162-linux-x64.tar.gz

 

1.4 set Environment Variables

 

[Root @ localhost java] # vim/etc/profile

 

Add the following content to profile:

 

# Set java environment

JAVA_HOME =/usr/java/jdk1.8.0 _ 162

JRE_HOME =/usr/java/jdk1.8.0 _ 162/jre

CLASS_PATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar: $ JRE_HOME/lib

PATH = $ PATH: $ JAVA_HOME/bin: $ JRE_HOME/bin

Export JAVA_HOME JRE_HOME CLASS_PATH PATH

 

Make the modification take effect:

[Root @ localhost java] # source/etc/profile

 

1.5 verify JDK Validity

 

[Root @ localhost java] # java-version

 

 

2. Install Git

 

2.1 install the GCC software suite

Used to compile git. If it is installed, ignore it.

Yum install gcc

 

2.2 download and install Git

Check that no git rpm package has been installed currently (uninstall if any)

Yum remove git

 

Install required Dependencies

Yum-y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker wget

 

 

Download and compile git

 

Cd/usr/local/src/

Wget https://www.kernel.org/pub/software/scm/git/git-2.15.1.tar.gz

Tar zxf git-2.15.1.tar.gz

Cd git-2.15.1

./Configure

Make prefix =/usr/local/git all

Make prefix =/usr/local/git install

 

In order.

 

Add git variable

Echo "export PATH = $ PATH:/usr/local/git/bin">/etc/bashrc

 

Make settings take effect

Source/etc/bashrc

 

View git version

Git -- version

 

View git location

Which git

 

 

3. Install jenkins3.1

Wget-O/etc/yum. repos. d/jenkins. repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

Rpm -- import https://jenkins-ci.org/redhat/jenkins-ci.org.key

Yum install jenkins

 

Or

Wget-O/etc/yum. repos. d/jenkins. repo https://pkg.jenkins.io/redhat/jenkins.repo

Rpm -- import https://pkg.jenkins.io/redhat/jenkins.io.key

Yum install jenkins

We recommend that you use the first method.

 

3.2 start Jenkins

 

Modify the Jenkins STARTUP configuration file and specify the java installation path.

Vim/etc/init. d/jenkins

 

Add the java path in the first line of candidates as follows:

 

Candidates ="

/Usr/java/jdk1.8.0 _ 162/bin/java

/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

"

 

 

Modify Jenkins Port

Vim/etc/sysconfig/jenkins

 

 

 

Service jenkins start/stop/restart

Chkconfig jenkins on

Chkconfig -- list | grep jenkins

Jenkins 0: off 1: off 2: on 3: on 4: on 5: on 6: off

 

 

3.3 Set firewall

 

Modify the firewall to allow access from port 8080

Vim/etc/sysconfig/iptables

 

Join

-A input-p tcp-m state -- state NEW-m tcp -- dport 9090-j ACCEPT

 

Press I to edit and Press Esc. Then enter wq and press enter to save and exit.

 

Restart firewall: sudo service iptables restart

Save firewall settings: sudo service iptables save

Permanently disable the firewall: chkconfig iptables off

Enable Firewall permanently: chkconfig iptables on

 

Open firewall: service iptables start

Disable firewall: service iptables stop

View the Firewall status: service iptables status

 

Enter the IP address + 8080 to access jenkins

 

3.4 error Solution

1: Lost Password

The jenkins logon password is in this file.

 

Vi/var/lib/jenkins/secrets/initialAdminPassword

Cat/var/lib/jenkins/secrets/initialAdminPassword

2: a prompt is displayed, indicating that the shell script has no permission.

Modify the owner.

1) vim/etc/sysconfig/jenkins

 

2) Change $ JENKINS_USER to "root ":

$ JENKINS_USER = "root"

 

3) then change the ownership of Jenkins home, webroot, and log:

chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins

 

4) Restart Jenkins and check whether the user has been changed

service jenkins restart

 

3: The instance is started successfully and cannot enter the system.

1. It is probably caused by a port conflict. Check the port first.

2. The firewall is not properly configured.

 

4. Quickly configure basic Jenkins4.1 settings

1: The first time you log on to the system, you need to unlock it.

 

 

View the file and copy the password

Cat/var/lib/jenkins/secrets/initialAdminPassword

 

 

2: Select plug-in Installation

 

 

Cancel all selections (directly go to the system without adding a plug-in)

 

3: Set the Administrator account to enter the system

 

 

4.2 install plug-ins

-Configure email notification

Email Extension Plugin

-Pull code
Git plugin

-Build the SDK in time after hook push is set
Gitlab Authentication plugin

Gitlab HookPlugin

GitLab Plugin

-Backup and Restoration

ThinBackup

 

Go to system management, Click Manage plug-ins, and click the optional plug-ins to find the corresponding plug-ins and click Install directly.

 

 

 

 

 

4.3 set plug-ins

Configure java and git to implement code pulling.

 

 

Enter the actual address for the name and JAVA_HOME. /Usr/java/jdk1.8.0 _ 162

Path to Git executable fill in the Path of the Git executable file. Setting Error pulling code will cause an error.

This is/usr/local/git/bin/git

Use which git to view the path

 

Save the settings.

 

4.4 configure email

To enable email notification

First go to system settings

 

 

Set Email:

SMTP server: smtp.exmail.qq.com

Ruanjianbu@hfhjzddata.com

Hjzd @*****

Default Subject: Build notification: $ {BUILD_STATUS}-$ {PROJECT_NAME}-Build #$ {BUILD_NUMBER }!

Default Content:

 

<! DOCTYPE html>

<Html>

<Head>

<Meta charset = "UTF-8">

<Title >$ {ENV, var = "JOB_NAME"}-build log No. $ {BUILD_NUMBER} </title>

<Style>

B {

Font-size: 16px;

}

Td {

Font-size: 16px;

}

Li {

Font-size: 16px;

}

</Style>

</Head>

<Body leftmargin = "8" marginwidth = "0" topmargin = "8" marginheight = "4"

Offset = "0">

<Table width = "95%" cellpadding = "0" cellspacing = "0"

Style = "font-size: 20px; font-family: Tahoma, Arial, Helvetica, sans-serif">

<Tr>

<Td> (this email is automatically sent by the program. Please do not reply !) </Td>

</Tr>

<Tr>

<Td>

<Fontcolor = "# 0000FF"> build result-$ {BUILD_STATUS} </font>

</H2> </td>

</Tr>

<Tr>

<Td> <br/>

<B> <fontcolor = "# 0B610B"> build Information </font> </B>

<Hr size = "2" width = "100%" align = "center"/> </td>

</Tr>

<Tr>

<Td>

<Ul>

<Li> Project name: $ {PROJECT_NAME} </li>

<Li> build No.: Build No. $ {BUILD_NUMBER} </li>

<Li> CAUSE: $ {CAUSE} </li>

<Li> build log: <ahref = "$ {BUILD_URL} console" >$ {BUILD_URL} console </a> </li>

<Li> build Url: <ahref = "$ {BUILD_URL}" >$ {BUILD_URL} </a> </li>

<Li> working directory: <ahref = "$ {PROJECT_URL} ws" >$ {PROJECT_URL} ws </a> </li>

<Li> project Url: <ahref = "$ {PROJECT_URL}" >$ {PROJECT_URL} </a> </li>

</Ul>

</Td>

</Tr>

<Tr>

<Td> <B> <fontcolor = "# 0B610B"> change set </font> </B>

<Hr size = "2" width = "100%" align = "center"/> </td>

</Tr>

<Tr>

<Td >$ {JELLY_SCRIPT, template = "html"} <br/>

<Hr size = "2" width = "100%" align = "center"/> </td>

</Tr>

</Table>

</Body>

</Html>

 

The system can test whether the email settings are successful.

 

Multiple default mailboxes are separated by commas. Set and save the settings.

 

5. Create and configure a project

 

5.1 create a project and configure the Git Library

Enter a project name and select a free style

 

 

2: Select git for source code management, enter the library address, add the account password, and enter the branch name.

 

Click Add to Add a git account and password

 

If an error is reported, view the error prompt.

 

The system prompts that the host cannot be resolved and the domain name is not configured.

Modify the hosts file

Vim/etc/hosts

Add Domain Name

 

 

5.2 set building trigger

First, compare the partition time with the git database, and immediately trigger the build if any change is found.

 

Select the Poll SCM input H/3 *** '3' as the build trigger to compare the three types.

 

Type 2: Set the git hook to trigger the build immediately after a push event occurs.

 

Check Build when achange is pushed to GitLab. GitLab CI Service URL :.......

Select "advanced" and click "generate" to generate a Secret token.

Copy the Secret token, And the GitLab CI Service URL needs to go to git to configure the web hook for use.

(The URLs and tokens of different projects are different)

 

 

 

 

 

Gitlab hook settings

Gitlab version 10.1

1: Enter the project selection settings

2: Select integration in settings

3: Enter the corresponding URL and token in the input box.

4: Cancel SSH authentication. Save the verification.

This hook is triggered every time the push takes effect and Jenkins is requested to execute the build task.

Different versions are set differently. This setting is suitable for new versions of gitlab and Jenkins.

 

 

 

 

 

5.3 build step settings

 

SelectExecuteshell

Enter the execution script

Example: rm-f/var/lib/jenkins/workspace/OPM/common/config/main-local.php & cp-Rf/var/lib/jenkins/workspace/OPM/*/home/htdocs opm-it.hjzd.com

 

The script is executed after the code is pulled.

 

5.4 add post-build operations

You can set email notification for building results.

Post-build operation selectionEditable Email Notification

 

 

 

 

 

Pay attention to the following three points:

 

Click "Advanced Settings" under the email to configure mail trigger conditions.

 

Select all trigger conditions

 

After the setting is successful, click build now on the homepage to check whether the email is successfully sent after the build.

 

 

 

The template for successfully sent emails is:

 

 

 

View the build log in the console output.

The hook is triggered successfully, and the build is successful. If the email is sent successfully, the project is configured successfully.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.