Jenkins 使用备忘

安装 Jenkins

使用 Homebrew 安装Jenkins。

1
brew install jenkins

启动 Jenkins

直接在终端输入如下命令启动

1
jenkins

当终端输出的日志最后显示如下所示,表示启动成功。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
信息:

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

8c3545925a714342acb94cdad830fcdc

This may also be found at: /Users/davidsheh/.jenkins/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************
信息: Jenkins is fully up and running

这里只拷贝了部分日志,注意*号之间的内容里包含一个默认的密码,下面会用到。

进入 Jenkins

当启动 Jenkins 后,打开浏览器,在地址栏输入 localhost:8080 后进入 Jenkins 图形界面。然后在 Administrator password 输入终端打印的那个密码。

安装插件

如果遇到插件列表无法安装或更新,可以进入到
Jenkins -> Manage Jenkins -> Configure Global Security 管理页面,找到 Plugin Manager 选项下的 Use browser for metadata download 并勾选。

安装插件

如果遇到插件列表无法安装或更新,可以进入到
Jenkins -> Manage Jenkins -> Configure System 管理页面,找到 Locale 选项,在输入框中输入 zh_CN ,并勾选 Ignore browser preference and force this language to all users

停止 Jenkins

进入终端,使用快捷键 Ctrl + C 可以停止 Jenkins。

FAQ

启动 Jenkins 时有警告出现,警告信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
三月 11, 2018 8:43:57 下午 hudson.model.AsyncPeriodicWork$1 run
信息: Finished Download metadata. 20,269 ms
三月 11, 2018 8:43:58 下午 hudson.model.UpdateCenter updateDefaultSite
警告: Upgrading Jenkins. Failed to update the default Update Site 'default'. Plugin upgrades may fail.
java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at hudson.model.DownloadService.loadJSON(DownloadService.java:167)
at hudson.model.UpdateSite.updateDirectlyNow(UpdateSite.java:190)
at hudson.model.UpdateCenter.updateDefaultSite(UpdateCenter.java:2194)
at jenkins.install.SetupWizard.init(SetupWizard.java:173)
at jenkins.install.InstallState$InitialSecuritySetup.initializeState(InstallState.java:142)
at jenkins.model.Jenkins.setInstallState(Jenkins.java:1035)
at jenkins.install.InstallUtil.proceedToNextStateFrom(InstallUtil.java:97)
at jenkins.install.InstallState$Unknown.initializeState(InstallState.java:75)
at jenkins.model.Jenkins.<init>(Jenkins.java:923)
at hudson.model.Hudson.<init>(Hudson.java:85)
at hudson.model.Hudson.<init>(Hudson.java:81)
at hudson.WebAppMain$3.run(WebAppMain.java:233)

三月 11, 2018 8:43:58 下午 hudson.UDPBroadcastThread run
信息: Cannot listen to UDP port 33,848, skipping: java.net.SocketException: Can't assign requested address
三月 11, 2018 8:43:58 下午 hudson.WebAppMain$3 run

原因是因为 GFW 把对应的 IP 给墙了。我的解决方案是,使用 Ctrl + C 停止 Jenkins,然后使用命令 rm -rf ~/.jenkins/ 删除 Jenkins 配置文件,然后打开翻墙工具,重新使用 jenkins 命令启动 Jenkins,然后问题解决了。另外一个方案是采用离线安装插件的方式,链接点这里

更换界面主题

https://devopscube.com/setup-custom-materialized-ui-theme-jenkins/

备份 Jenkins 配置

使用 Thin Backup 插件备份配置。链接:
https://devopscube.com/jenkins-backup-data-configurations/