Ubuntu 16.04 安裝 Jenkins

劉校發表於2017-09-19

安裝、啟動並配置jenkins服務

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c `echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list`
sudo apt-get update
sudo apt-get install jenkins
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 ago

 Docs: 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

訪問路徑:http://localhost:8089

其他說明

  • 安裝路徑:/var/lib/jenkins
  • 日誌路徑:/var/log/jenkins/jenkins.log

二、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安裝,那麼就需要自己根據業務需要選擇性安裝某些外掛。

3)建立第一個管理員使用者

說明:這裡建立第一個管理員使用者,也可以不設定,直接點選“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$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>

:密碼為111111

相關文章