ubuntu 16.04安装Jenkins

转载请注明出处:http://blog.csdn.net/heng615975867/article/details/52759779

一.前言

在ubuntu 16.04 service版本上搭建jenkins来管理自动化编译,查阅了很多博客,发现都是ctrl+v的,到处踩坑,不断爬坑,所以出此博客帮助需要的同志少走弯路。

二.先安装JAVA JDK

check jdk:
  1. xulongheng @ubuntu:/usr/lib/jvm$ java -version
  2. openjdk version "1.8.0_91"
  3. OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
  4. OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)


三.Jenkins安装


有两张安装方式,

方式一:war包安装


去Jenkins官网(https://jenkins.io/index.html)下载Jenkins.war 包  启动tomcat就可以了。
访问:http://localhost:8080/jenkins

方式二:apt install 安装

1.我们可以手动从这个链接下载稳定的版本, 添加Debian库和关键的系统。 这一步可以自动安装:
<pre name="code" class="java" style="color: rgb(85, 85, 85); line-height: 35px;font-size:18px;">xulongheng@ubuntu<span style="color: rgb(51, 51, 51); font-family: 'microsoft yahei', simhei, arial, sans-serif; font-size: 16px; line-height: 20px;">:~# sudo wget -q -O - http://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -</span>
OK
 
  
2.然后添加Debian pacakage到源清单 /etc/apt/sources.list.d
xulongheng@ubuntu:~# sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

3.最后升级获取最新推出稳定版本的Jenkins
  1. xulongheng @ubuntu:~# sudo apt-get update
  2. <pre name= "code" class= "java" style= "color: rgb(51, 51, 51); font-size: 16px; line-height: 20px;">xulongheng @ubuntu:<span style= "font-family: 'microsoft yahei', simhei, arial, sans-serif;">~# sudo apt-get install jenkins</span>
 
   
4.服务的启动/停止:
  1. <span style= "font-size:18px;">sudo service jenkins start
  2. sudo service jenkins stop </span>

5.路径:
访问路径:http://localhost:8080  
安装路径:/var/lib/jenkins  
日志路径:/var/log/jenkins
创建的项目目录当然在jenkins安装目录下的jobs里面。

6.启动Jenkins服务
  1. <span style= "font-size:18px;">xulongheng @ubuntu:~# service jenkins start
  2. Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.</span>

7.服务启动失败,按照提示排除错误原因

  1. xulongheng @ubuntu:~# systemctl status jenkins.service
  2. ● jenkins.service - LSB: Start Jenkins at boot time
  3. Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled)
  4. Active: failed (Result: exit-code) since Thu 2016- 10- 08 15: 08: 40 IST; 9s ago
  5. Docs: man:systemd-sysv-generator( 8)
  6. Process: 25640 ExecStart=/etc/init.d/ jenkins start (code=exited, status=7)
  7. Oct 08 15:08:39 systemsguru systemd[1]: Starting LSB: Start Jenkins at boot time...
  8. Oct 08 15:08:39 systemsguru jenkins[25640]: * Starting Jenkins Continuous Integration Server jenkins
  9. Oct 08 15:08:39 systemsguru jenkins[25640]: The selected http port (8080) seems to be in use by another program
  10. Oct 08 15:08:39 systemsguru jenkins[25640]: Please select another port to use for jenkins
  11. Oct 08 15:08:40 systemsguru jenkins[25640]: ...fail!
  12. Oct 08 15:08:40 systemsguru systemd[1]: jenkins.service: Control process exited, code=exited status= 7
  13. Oct 08 15: 08: 40 systemsguru systemd[ 1]: Failed to start LSB: Start Jenkins at boot time.
  14. Oct 08 15: 08: 40 systemsguru systemd[ 1]: jenkins.service: Unit entered failed state.
  15. Oct 08 15: 08: 40 systemsguru systemd[ 1]: jenkins.service: Failed with result 'exit-code'.
  16. xulongheng @ubuntu:~# cat /etc/services | grep 8080
  17. http-alt 8080/tcp webcache # WWW caching service
  18. http-alt 8080/udp

8. 从日志看出Jenkins在默认情况下从8080端口启动。在这个系统端口中,8080已经在使用中了。所以在/etc/default/jenkins.修改Jenkins默认端口设置

xulongheng@ubuntu:~# nano /etc/default/jenkins

修改默认端口为  HTTP_PORT=8090


9.我们再来试试启动Jenkins

  1. xulongheng @ubuntu:~$ sudo service jenkins start
  2. [sudo] password for xulongheng:
  3. xulongheng @ubuntu:~$ sudo service jenkins start
  4. xulongheng @ubuntu:~$ sudo service jenkins status
  5. [ 0m jenkins.service - LSB: Start Jenkins at boot time
  6. Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled)
  7. Active: active (exited) since Sat 2016- 10- 08 17: 52: 51 CST; 1h 41min ago
  8. Docs: man:systemd-sysv-generator( 8)
  9. Process: 22519 ExecStart=/etc/init.d/ jenkins start (code=exited, status=0/SUCCESS)
  10. Oct 08 17:52:50 ubuntu systemd[1]: Starting LSB: Start Jenkins at boot time...
  11. Oct 08 17:52:50 ubuntu jenkins[22519]: * Starting Jenkins Continuous Integration Server jenkins
  12. Oct 08 17:52:50 ubuntu su[22538]: Successful su for jenkins by root
  13. Oct 08 17:52:50 ubuntu su[22538]: + ??? root:jenkins
  14. Oct 08 17:52:50 ubuntu su[22538]: pam_unix(su:session): session opened for user jenkins by (uid=0)
  15. Oct 08 17:52:51 ubuntu jenkins[22519]: ...done.
  16. Oct 08 17:52:51 ubuntu systemd[1]: Started LSB: Start Jenkins at boot time.
  17. Oct 08 19:10:32 ubuntu systemd[1]: Started LSB: Start Jenkins at boot time.
  18. Oct 08 19:34:29 ubuntu systemd[1]: Started LSB: Start Jenkins at boot time.
  19. Oct 08 19:34:33 ubuntu systemd[1]: Started LSB: Start Jenkins at boot time.
  20. xulongheng@ubuntu:~$ ps -ef | grep jenkins
  21. jenkins 22539 1 0 17:52 ? 00:00:00 /lib/systemd/systemd --user
  22. jenkins 22541 22539 0 17:52 ? 00:00:00 (sd-pam)
  23. jenkins 22547 1 0 17:52 ? 00:00:00 /usr/bin/daemon --name=jenkins --inherit --env=JENKINS_HOME=/var/lib/jenkins --output=/var/log/jenkins/jenkins.log --pidfile=/var/run/jenkins/jenkins.pid -- /usr/bin/java -Djava.awt.headless= true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort= 8090
  24. jenkins 22548 22547 1 17: 52 ? 00: 01: 05 /usr/bin/java -Djava.awt.headless= true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort= 8090
  25. xulongh+ 30755 30553 0 19: 35 pts/ 0 00: 00: 00 grep --color=auto jenkins
  26. xulongheng @ubuntu:~$
Jenkins service started successfully on port 8090

10.创建Jenkins,在浏览器里面输入:http://192.168.1.16:8090/出现下面界面



这里需要/var/lib/jenkins/secrets/initialAdminPassword的密码解锁Jenkins

root@systemsguru:~# cat /var/lib/jenkins/secrets/initialAdminPassword
然后把密码复制进去。

选择默认的插件



创建用户



Jenkins安装成功


11.Jenkins卸载
sudo apt-get remove –auto-remove jenkins


四.Jenkins配置

关于Jenkins配置与使用请参考文档



猜你喜欢

转载自blog.csdn.net/twyth1214/article/details/80989671