背景
Build great things at any scale The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
其是一款开源自动化部署服务器,由java编写,目的是为了持久集成。
具体步骤
- 项目和远程仓库
- 将最新的代码推送到远程仓库
- 远程仓库和Jenkins
- 定时获取远程仓库上最新的完整项目下载到本地
- Jenkins与远程服务器
- 通过jenkins上传到远程服务器
安装
先添加其Debian
软件包,然后更新存储库,最后使用存储库apt-get
安装jenkins
。
安装运行环境
安装jdk
sudo apt-get install openjdk-8-jdk
复制代码
安装完成如下
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer to provide /usr/bin/appletviewer (appletviewer) in auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ca-certificates (20170717~16.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
done.
复制代码
存储库密钥添加到系统
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
复制代码
出现ok
,添加成功
Debian包存储库地址添加到服务器sources.list
echo deb http://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
复制代码
添加成功如下
deb http://pkg.jenkins.io/debian-stable binary/
复制代码
更新存储库
sudo apt-get update
复制代码
更新成功如下
Ign:17 http://pkg.jenkins.io/debian-stable binary/ InRelease
Get:18 http://pkg.jenkins.io/debian-stable binary/ Release [2042 B]
Get:19 http://pkg.jenkins.io/debian-stable binary/ Release.gpg [181 B]
Ign:20 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 InRelease
Hit:21 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 Release
Get:23 http://pkg.jenkins.io/debian-stable binary/ Packages [14.7 kB]
Fetched 6813 kB in 3s (2187 kB/s)
Reading package lists... Done
复制代码
安装jenkins
sudo apt-get install jenkins
复制代码
安装成功如下
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package daemon.
(Reading database ... 136881 files and directories currently installed.)
Preparing to unpack .../daemon_0.6.4-1_amd64.deb ...
Unpacking daemon (0.6.4-1) ...
Selecting previously unselected package jenkins.
Preparing to unpack .../jenkins_2.164.2_all.deb ...
Unpacking jenkins (2.164.2) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up daemon (0.6.4-1) ...
Setting up jenkins (2.164.2) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
复制代码
修改默认端口8080
- 修改
/etc/init.d/jenkins
脚本
sudo vim /etc/init.d/jenkins
复制代码
修改$HTTP_PORT
改成所需的端口
# Verify that the jenkins port is not already in use, winstone does not exit
# even for BindException
check_tcp_port "http" "$HTTP_PORT" "1314" "$HTTP_HOST" "0.0.0.0" || return 2
# If the var MAXOPENFILES is enabled in /etc/default/jenkins then set the max open files to the
# proper value
复制代码
- 修改
/etc/default/jenkins
文件