说起来,Jenkins其实和Linux自带的crontab有点像,都是满足特定条件后执行脚本。但是Jenkins触发任务的形式更加灵活,并不局限于定时,所以还是很有用的。
安装
按照惯例,遇到Linux的问题先说环境:系统是Ubuntu16.04,已经提前安装了JDK 1.8,没有用docker,并且已经打开了防火墙。有时候安装好了但访问不了,就是因为防火墙没打开。
其实安装流程很简单,按照官网的流程走一遍就行:
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
如果这么安装能成功,那最好了。但是往往会遇到各种问题。我遇到的报错信息是这样:
Aug 06 22:33:57 iZuf699cacb5hvp8me6ft6Z systemd[1]: Starting LSB: Start Jenkins at boot time...
Aug 06 22:33:57 iZuf699cacb5hvp8me6ft6Z jenkins[24569]: ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin
Aug 06 22:33:57 iZuf699cacb5hvp8me6ft6Z jenkins[24569]: If you actually have java installed on the system make sure the executable is in the aforementioned path and that 'type -p java' re
Aug 06 22:33:57 iZuf699cacb5hvp8me6ft6Z systemd[1]: jenkins.service: Control process exited, code=exited status=1
Aug 06 22:33:57 iZuf699cacb5hvp8me6ft6Z systemd[1]: Failed to start LSB: Start Jenkins at boot time.
Aug 06 22:33:57 iZuf699cacb5hvp8me6ft6Z systemd[1]: jenkins.service: Unit entered failed state.
Aug 06 22:33:57 iZuf699cacb5hvp8me6ft6Z systemd[1]: jenkins.service: Failed with result 'exit-code'.
一开始我看到Start Jenkins at boot time
,以为是端口冲突,因为这个报错是网络问题,而且Jenkins的默认端口是8080,和服务器上已经有的Tomcat冲突了。所以修改Jenkins的配置文件,把端口改成8085:
# /etc/default/jenkins
HTTP_PORT=8085
# /etc/init.d/je