Jenkins 服务安装过程和介绍

2019-08-20 0 By admin

一、Jenkins特性

  1. 开源的java语言开发持续集成工具,支持CI,CD;
  2. 易于安装部署配置:可通过yum安装,或下载war包以及通过docker容器等快速实现安装部署,可方便web界面配置管理;
  3. 消息通知及测试报告:集成RSS/E-mail通过RSS发布构建结果或当构建完成时通过e-mail通知,生成JUnit/TestNG测试报告;
  4. 分布式构建:支持Jenkins能够让多台计算机一起构建/测试;
  5. 文件识别:Jenkins能够跟踪哪次构建生成哪些jar,哪次构建使用哪个版本的jar等;
  6. 丰富的插件支持:支持扩展插件,你可以开发适合自己团队使用的工具,如git,svn,maven,docker

二、Jenkins安装

安装最低配置:不少于256M内存,不低于1G磁盘,JDK版本>=8(openjdk也可以)。
[root@Jenkins ~]# yum install -y java-1.8.0-openjdk //安装openjdk,因为jenkins基于java开发
[root@Jenkins ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
[root@Jenkins ~]# rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key //安装jenkins key
[root@Jenkins ~]# yum install -y jenkins

三、启动jenkins

[root@Jenkins ~]# systemctl start jenkins
[root@Jenkins ~]# less /var/log/jenkins/jenkins.log //查看jenkins日志,截取下面部分
Jenkins initial setup is required. An admin user has been created and a password generated
Please use the following password to proceed to installation:
77faa20f2ad544f7bcb6593b1cf1436b //admin密码,初始化安装时会用到
This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword

四、程序主目录

[root@Jenkins ~]# ls /var/lib/jenkins/
config.xml
hudson.model.UpdateCenter.xml
hudson.plugins.git.GitTool.xml
identity.key.enc
jenkins.CLI.xml
jenkins.install.InstallUtil.lastExecVersion
jenkins.install.UpgradeWizard.state
jenkins.model.JenkinsLocationConfiguration.xml
jobs //浏览器上面创建的任务都会存放在这里
logs //存放jenkins相关的日志
nodeMonitors.xml
nodes //多节点时用到
plugins // 插件所在目录
queue.xml.bak
secret.key
secret.key.not-so-secret
secrets //密码秘钥所在目录
updates
userContent
users
workflow-libs

jenkins存放数据不依靠数据库,所以在移植时只需要拷贝整个程序主目录即可;另外jobs和plugins目录比较重要

五、查看jenkins的配置文件

查看jenkins的配置文件,定义了home、JAVA_CMD、user、port等基础配置,保持默认即可
[root@Jenkins ~]# cat /etc/sysconfig/jenkins
## Path: Development/Jenkins
## Description: Jenkins Automation Server
## Type: string
## Default: "/var/lib/jenkins"
## ServiceRestart: jenkins
#####
# Directory where Jenkins store its configuration and working
# files (checkouts, build reports, artifacts, ...).
JENKINS_HOME="/var/lib/jenkins"
#####
## Type: string
## Default: ""
# Java executable to run Jenkins
# When left empty, we'll try to find the suitable Java.
JENKINS_JAVA_CMD=""
#####
## Type: string
## Default: "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"
#####
## Type: string
## Default: "false"
# Whether to skip potentially long-running chown at the
# $JENKINS_HOME location. Do not enable this, "true", unless
# you know what you're doing. See JENKINS-23273.
#JENKINS_INSTALL_SKIP_CHOWN="false"
#####
## Type: string
## Default: "-Djava.awt.headless=true"
# Options to pass to java when running Jenkins.
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"
#####
## Type: integer(0:65535)
## Default: 8080
# Port Jenkins is listening on.
# Set to -1 to disable
JENKINS_PORT="8080"
#####
## Type: string
## Default: ""
# IP address Jenkins listens on for HTTP requests.
# Default is all interfaces (0.0.0.0).
JENKINS_LISTEN_ADDRESS=""
#####
## Type: integer(0:65535)
## Default: ""
# HTTPS port Jenkins is listening on.
# Default is disabled.
JENKINS_HTTPS_PORT=""
#####
## Type: string
## Default: ""
# Path to the keystore in JKS format (as created by the JDK 'keytool').
# Default is disabled.
JENKINS_HTTPS_KEYSTORE=""
#####
## Type: string
## Default: ""
# Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE.
# Default is disabled.
JENKINS_HTTPS_KEYSTORE_PASSWORD=""
#####
## Type: string
## Default: ""
# IP address Jenkins listens on for HTTPS requests.
# Default is disabled.
JENKINS_HTTPS_LISTEN_ADDRESS=""
#####
## Type: integer(1:9)
## Default: 5
# Debug level for logs -- the higher the value, the more verbose.
# 5 is INFO.
JENKINS_DEBUG_LEVEL="5"
#####
## Type: yesno
## Default: no
# Whether to enable access logging or not.
JENKINS_ENABLE_ACCESS_LOG="no"
#####
## Type: integer
## Default: 100
# Maximum number of HTTP worker threads.
JENKINS_HANDLER_MAX="100"
#####
## Type: integer
## Default: 20
# Maximum number of idle HTTP worker threads.
JENKINS_HANDLER_IDLE="20"
#####
## Type: string
## Default: ""
# Pass arbitrary arguments to Jenkins.
# Full option list: java -jar jenkins.war --help
JENKINS_ARGS=""