安装、启动并配置jenkins服务
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key |sudoapt-key add - sudosh -c'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' sudoapt-get update sudoapt-getinstalljenkins
systemctl status jenkins.service
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled)
Active: Failed (Result: exit-code) since 一 2017-09-18 20:02:02 CST; 5min agoDocs: man:systemd-sysv-generator(8)9月 18 20:02:02 DH9K45ER2 systemd[1]: Starting LSB: Start Jenkins at boot time...
9月 18 20:02:02 DH9K45ER2 jenkins[4785]: ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin
9月 18 20:02:02 DH9K45ER2 jenkins[4785]: If you actually have java installed on the system make sure the executable is in the aforementioned path and that 't
9月 18 20:02:02 DH9K45ER2 systemd[1]: jenkins.service: Control process exited,code=exited status=1
9月 18 20:02:02 DH9K45ER2 systemd[1]: Failed to start LSB: Start Jenkins at boot time.
9月 18 20:02:02 DH9K45ER2 systemd[1]: jenkins.service: Unit entered Failed state.
9月 18 20:02:02 DH9K45ER2 systemd[1]: jenkins.service: Failed with result 'exit-code'.
cat /etc/services | grep 8080
http-alt 8080/tcp webcache # WWW caching service
http-alt 8080/udp
从日志看出Jenkins在默认情况下从8080端口启动。在这个系统端口中,8080已经在使用中了。所以在/etc/default/jenkins.修改Jenkins默认端口设置
修改/etc/default/目录下面的jenkins
文件,将以下内容
# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=8080
修改为:
# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=8089
启动停止Jenkins
sudo service jenkins start sudo service jenkins stop
其他说明
- 安装路径:
/var/lib/jenkins
- 日志路径:
/var/log/jenkins/jenkins.log
@H_502_66@
二、Jenkins初始化配置
1)解锁Jenkins
这里需要/var/lib/jenkins/secrets/initialAdminPassword的密码解锁Jenkins
然后把密码复制进去。
说明:按照弹框提示,找到该initialAdminPassword文件,我这里使用Docker启动Jenkins,并且把jenkins_home目录挂载到我磁盘指定目录,所以这里我只需要复制/Users/wanyang3/jenkins_home/initialAdminPassword即可,如果非挂载方式Docker启动,则需要进入容器内根据提示路径找到该文件。
2)定制 Jenkins
说明:这里若选择Install suggested plugins安装,那么jenkins就会给你推荐安装一些很有用的插件,若选择Select plugins to install安装,那么就需要自己根据业务需要选择性安装某些插件。
说明:这里创建第一个管理员用户,也可以不设置,直接点击“Continue as admin”,进入jenkins以后再设置。
新建Pipeline Job Demo
1)创建一个pipeline job
/var/lib/jenkins/config.xml
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.GlobalMatrixAuthorizationSt
rategy">
<permission>hudson.model.Computer.Configure:admin</permission> <permission>hudson.model.Computer.Connect:admin</permission> <permission>hudson.model.Computer.Create:admin</permission> <permission>hudson.model.Computer.Delete:admin</permission> <permission>hudson.model.Computer.Disconnect:admin</permission> <permission>hudson.model.Hudson.Administer:admin</permission> <permission>hudson.model.Hudson.Read:admin</permission> <permission>hudson.model.Hudson.Read:anonymous</permission> <permission>hudson.model.Hudson.RunScripts:admin</permission> <permission>hudson.model.Item.Build:admin</permission> <permission>hudson.model.Item.Cancel:admin</permission> <permission>hudson.model.Item.Configure:admin</permission> <permission>hudson.model.Item.Create:admin</permission> <permission>hudson.model.Item.Delete:admin</permission> <permission>hudson.model.Item.Discover:admin</permission> <permission>hudson.model.Item.Read:admin</permission> <permission>hudson.model.Item.Workspace:admin</permission> <permission>hudson.model.Run.Delete:admin</permission> <permission>hudson.model.Run.Update:admin</permission> <permission>hudson.model.View.Configure:admin</permission> <permission>hudson.model.View.Create:admin</permission> <permission>hudson.model.View.Delete:admin</permission> <permission>hudson.model.View.Read:admin</permission> <permission>hudson.scm.SCM.Tag:admin</permission>
</authorizationStrategy>
<securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
<disableSignup>false</disableSignup> <enableCaptcha>false</enableCaptcha>
</securityRealm>
修改用户密码/var/lib/jenkins/users/user/config.xml<hudson.security.HudsonPrivateSecurityRealm_-Details> <passwordHash>#jbcrypt:$2a$10$GAPETE91o2RhcOOq7lA6HejyIW1FRfn9iuMSSCiJJd6WMYUKD3bWm</passwordHash></hudson.security.HudsonPrivateSecurityRealm_-Details>
原文链接:https://www.f2er.com/ubuntu/351224.html