本文主要是介绍5.Jenkins入门基础使用补充说明与相关问题总结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录一览:
-
0x05 补充说明
-
(1) 内置环境变量
-
(2) Jenkins 管理员密码忘记重置
-
(3) Jenkins 升级迁移
-
-
0x06 入坑&出坑
WeiyiGeek Blog - 为了能到远方,脚下的每一步都不能少。
Tips : 本文章来源 Blog 站点或者 WeiyiGeek
公众账号 (技术交流、友链交换请邮我哟
), 原文地址: 5.Jenkins入门基础使用补充说明与相关问题总结
- 微信公众号-WeiyiGeek # 精华文章发布地址(及时发布)
- 首页-https://weiyigeek.top # 采用cloudflare CDN 国内有时访问较慢
- https://weiyigeek.gitee.io # 国内访问快但可能会有更新不及时的情况
0x05 补充说明
(1) 内置环境变量
PS : Jenkins 默认的环境变量列表 http://jenkins.weiyigeek.top:8080/env-vars.html/
BUILD_NUMBER #The current build number, such as "153" BUILD_ID# The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds BUILD_DISPLAY_NAME# The display name of the current build, which is something like "#153" by default. JOB_NAME# Name of the project of this build, such as "foo" or "foo/bar". JOB_BASE_NAME# Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo". BUILD_TAG# String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification. EXECUTOR_NUMBER# The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1. NODE_NAME# Name of the agent if the build is on an agent, or "master" if run on master NODE_LABELS# Whitespace-separated list of labels that the node is assigned. WORKSPACE# The absolute path of the directory assigned to the build as a workspace. WORKSPACE_TMP# A temporary directory near the workspace that will not be browsable and will not interfere with SCM checkouts. May not initially exist, so be sure to create the directory as needed (e.g., mkdir -p on Linux). Not defined when the regular workspace is a drive root. JENKINS_HOME# The absolute path of the directory assigned on the master node for Jenkins to store data. JENKINS_URL# Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration) BUILD_URL# Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set) JOB_URL# Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set) GIT_COMMIT# The commit hash being checked out. GIT_PREVIOUS_COMMIT# The hash of the commit last built on this branch, if any. GIT_PREVIOUS_SUCCESSFUL_COMMIT# The hash of the commit last successfully built on this branch, if any. GIT_BRANCH# The remote branch name, if any. GIT_LOCAL_BRANCH# The local branch name being checked out, if applicable. GIT_CHECKOUT_DIR# The directory that the repository will be checked out to. This contains the value set in Checkout to a sub-directory, if used. GIT_URL# The remote URL. If there are multiple, will be GIT_URL_1, GIT_URL_2, etc. GIT_COMMITTER_NAME# The configured Git committer name, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.name Value field of the Jenkins Configure System page. GIT_AUTHOR_NAME# The configured Git author name, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.name Value field of the Jenkins Configure System page. GIT_COMMITTER_EMAIL# The configured Git committer email, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.email Value field of the Jenkins Configure System page. GIT_AUTHOR_EMAIL# The configured Git author email, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.email Value field of the Jenkins Configure System page.
测试环境变量:
#!/bin/bash echo BUILD_NUMBER: ${BUILD_NUMBER }echo BUILD_ID: ${BUILD_ID}echo BUILD_DISPLAY_NAME: $BUILD_DISPLAY_NAME:echo JOB_NAME: $JOB_NAMEecho JOB_BASE_NAME: $JOB_BASE_NAMEecho BUILD_TAG: $BUILD_TAGecho EXECUTOR_NUMBER: $EXECUTOR_NUMBERecho NODE_NAME: $NODE_NAMEecho NODE_LABELS: $NODE_LABELSecho WORKSPACE: $WORKSPACEecho WORKSPACE_TMP: $WORKSPACE_TMPecho JENKINS_HOME: $JENKINS_HOMEecho JENKINS_URL: $JENKINS_URLecho BUILD_URL: $BUILD_URLecho JOB_URL: $JOB_URLecho GIT_COMMIT: $GIT_COMMITecho GIT_PREVIOUS_COMMIT: $GIT_PREVIOUS_COMMITecho GIT_PREVIOUS_SUCCESSFUL_COMMIT: $GIT_PREVIOUS_SUCCESSFUL_COMMITecho GIT_BRANCH: $GIT_BRANCHecho GIT_LOCAL_BRANCH: $GIT_LOCAL_BRANCHecho GIT_CHECKOUT_DIR: $GIT_CHECKOUT_DIRecho GIT_URL: $GIT_URLecho GIT_COMMITTER_NAME: $GIT_COMMITTER_NAMEecho GIT_AUTHOR_NAME: $GIT_AUTHOR_NAMEecho GIT_COMMITTER_EMAIL: $GIT_COMMITTER_EMAILecho GIT_AUTHOR_EMAIL: $GIT_AUTHOR_EMAIL
测试结果:
+ /bin/bash /tmp/script/env.sh BUILD_NUMBER: 22 BUILD_ID: 22 BUILD_DISPLAY_NAME: #22: JOB_NAME: Maven-HelloWorld JOB_BASE_NAME: Maven-HelloWorld BUILD_TAG: jenkins-Maven-HelloWorld-22 EXECUTOR_NUMBER: 0 NODE_NAME: master NODE_LABELS: master WORKSPACE: /var/lib/jenkins/workspace/Maven-HelloWorld WORKSPACE_TMP: /var/lib/jenkins/workspace/Maven-HelloWorld@tmp JENKINS_HOME: /var/lib/jenkins JENKINS_URL: http://jenkins.weiyigeek.top:8080/ BUILD_URL: http://jenkins.weiyigeek.top:8080/job/Maven-HelloWorld/22/ JOB_URL: http://jenkins.weiyigeek.top:8080/job/Maven-HelloWorld/ GIT_COMMIT: 0f50b10b09c160a86972178d94ca1f0a704dd767 GIT_PREVIOUS_COMMIT: 0f50b10b09c160a86972178d94ca1f0a704dd767 GIT_PREVIOUS_SUCCESSFUL_COMMIT: 0f50b10b09c160a86972178d94ca1f0a704dd767 GIT_BRANCH: v1.7 GIT_URL: git@gitlab.weiyigeek.top:ci-cd/java-maven.git GIT_AUTHOR_NAME: GIT_AUTHOR_EMAIL: GIT_COMMITTER_NAME: GIT_COMMITTER_EMAIL: GIT_LOCAL_BRANCH: GIT_CHECKOUT_DIR: Finished: SUCCESS
(2) Jenkins 管理员密码忘记重置
1.找到用户的路径
[root@jenkins-node1 ~]# cd /var/lib/jenkins/users/ [root@jenkins-node1 users]# tree . ├── 552408925_8628634723176281851 │ └── config.xml ├── admin_8092868597319509744 │ └── config.xml ├── jenkins_3327043579358903316 #我使用的jenkins作为管理员(如果你是admin就进admin目录) │ └── config.xml #修改config.xml └── users.xml3 directories, 4 files
2.修改jenkins用户目录下的config.xml,定位到<passwordHash>
那行删除,改为如下内容-
[root@jenkins-node1 users]# vim config.xml <passwordHash>#jbcrypt:$2a$10$slYx6.2Xyss6w9LnuiwnNOReuvkcSkaI.Y.Z2AC6Sp7hdF7hhxlsK</passwordHash>
3.新密码为bgx.com 记得重启jenkins生效
(3) Jenkins 升级迁移
描述: 在使用 Jenkins 时候显示新版本的 Jenkins (2.272) 可以下载 (变更记录),正好可以实践一哈Jenkins的升级&迁移。
PS : 如果是是在生产环境中升级建议慎重,可能会导致插件和升级版本不兼容的情况;
操作流程:
# (1) 下载更新包 wget https://updates.jenkins.io/download/war/2.272/jenkins.war # (2) 停止 Jenkins 服务 jenkins:/usr/share/jenkins# systemctl stop jenkins && ls# jenkins.war# (3) 备份上一个版本 jenkins:/usr/share/jenkins# mv jenkins.war jenkins.war.2.263.1.bak jenkins:/usr/share/jenkins# cp /home/weiyigeek/jenkins.war jenkins.war jenkins:/usr/share/jenkins# ls -alh# -rw-r--r-- 1 root root 67M Dec 24 02:38 jenkins.war# -rw-r--r-- 1 root root 65M Dec 2 13:56 jenkins.war.2.263.1.bak# (4) 启动 Jenkins 服务 jenkins:/usr/share/jenkins# systemctl start jenkins jenkins:/usr/share/jenkins# systemctl status jenkins# ● jenkins.service - LSB: Start Jenkins at boot time# Loaded: loaded (/etc/init.d/jenkins; generated)# Active: active (exited) since Thu 2020-12-24 02:38:50 UTC; 4s ago# Docs: man:systemd-sysv-generator(8)# Process: 448375 ExecStart=/etc/init.d/jenkins start (code=exited, status=0/SUCCESS)# Dec 24 02:38:48 gitlab systemd[1]: Starting LSB: Start Jenkins at boot time...# Dec 24 02:38:48 gitlab jenkins[448375]: Correct java version found# Dec 24 02:38:48 gitlab jenkins[448375]: * Starting Jenkins Automation Server jenkins# Dec 24 02:38:48 gitlab su[448432]: (to jenkins) root on none# Dec 24 02:38:48 gitlab su[448432]: pam_unix(su-l:session): session opened for user jenkins by (uid=0)# Dec 24 02:38:49 gitlab su[448432]: pam_unix(su-l:session): session closed for user jenkins# Dec 24 02:38:50 gitlab jenkins[448375]: ...done.# Dec 24 02:38:50 gitlab systemd[1]: Started LSB: Start Jenkins at boot time.# (5) 访问 Jenkins UI 界面验证升级版本 http://jenkins.weiyigeek.top:8080/about/
0x06 入坑&出坑
问题1.jenkins depends on daemon; however Package daemon is not installed.
问题描述: 在Ubuntu 采用 dpkg 安装 jenkins_2.263.1_all.deb 时报错提示 daemon 包未安装
问题复原:
$ sudo dpkg -i jenkins_2.263.1_all.deb Selecting previously unselected package jenkins. (Reading database ... 115038 files and directories currently installed.) Preparing to unpack jenkins_2.263.1_all.deb ... Unpacking jenkins (2.263.1) ... dpkg: dependency problems prevent configuration of jenkins:jenkins depends on daemon; however:Package daemon is not installed.dpkg: error processing package jenkins (--install):dependency problems - leaving unconfigured Processing triggers for systemd (245.4-4ubuntu3.2) ... Errors were encountered while processing:jenkins
解决办法:
sudo apt install -y daemon
问题2:Jenkins 启动时显示 ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin
问题复原:
$ systemctl status jenkins Dec 23 14:02:57 gitlab systemd[1]: Starting LSB: Start Jenkins at boot time... Dec 23 14:02:57 gitlab jenkins[356298]: ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin Dec 23 14:02:57 gitlab jenkins[356298]: If you actually have java installed on the system make sure the executable is in the aforementioned path and that 'type -p ja> Dec 23 14:02:57 gitlab systemd[1]: jenkins.service: Control process exited, code=exited, status=1/FAILURE Dec 23 14:02:57 gitlab systemd[1]: jenkins.service: Failed with result 'exit-code'. Dec 23 14:02:57 gitlab systemd[1]: Failed to start LSB: Start Jenkins at boot time.
问题原因: 未找寻到有效的Java执行环境;
解决流程:
①.先执行echo $PATH 看看环境变量运行结果如下:
/usr/maven/maven/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/java/jdk1.8/bin
如果连这都没有的话重新安装Java。②.建立软连接:ln -s /usr/java/jdk1.8/bin/java /usr/bin/java(换成你自己的路径)
Please wait while Jenkins is getting ready to work (jenkins)
如果界面提示Jenkins正在启动,请稍后…或者提示
Please wait while Jenkins is getting ready to work…
问题3.安装Jenkins后或者安装插件时候一直在加载;
问题描述: 由于Jenkins官方插件下载地址没被墙但是网速很慢,下载时间也长;
解决方法:换清华的镜像进去之后下载插件即可 (http://updates.jenkins-ci.org/download/)
操作流程: 需要你进入jenkins的工作目录
# 打开 hudson.model.UpdateCenter.xml 把 http://updates.jenkins-ci.org/update-center.json 改成 http://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json sed -i "s#updates.jenkins.io#mirrors.tuna.tsinghua.edu.cn/jenkins/updates#g" /var/lib/jenkins/hudson.model.UpdateCenter.xml# 上面的命令就是将将安装目录下的 hudson.model.UpdateCenter.xml 中改成 <?xml version='1.1' encoding='UTF-8'?> <sites><site><id>default</id><url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url></site> </sites># (2) 将updates文件夹下的default.json 中所有 http://updates.jenkins-ci.org/download/替换为 https://mirrors.tuna.tsinghua.edu.cn/jenkins/ PS: 也可以在后台进行设置 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json# (3) 修改完成后重启 Jenkins 即可
问题4: 未正确配置Jenkins基础URL等相关信息;
问题描述: Jenkins的根URL是空的,但是需要Jenkins的许多特性的正确操作,如电子邮件通知、PR状态更新和环境变量,如BUILD_URL。
请提供Jenkins配置中的准确值。
Jenkins root URL is empty but is required for the proper operation of many Jenkins features like email notifications, PR status update, and environment variables such as BUILD_URL.Please provide an accurate value in Jenkins configuration.
解决办法: Dashboard -> 配置 -> Jenkins Location -> Jenkins 地址 & 邮箱
问题5.无法连接仓库:Command "git ls-remote -h -- git@gitlab.weiyigeek.top:ci-cd/blog.git HEAD" returned status code 128:
问题复原:
stdout:stderr: Host key verification failed.fatal: Could not read from remote repository. # Please make sure you have the correct access rights and the repository exists.
问题原因: 由于采用SSH协议进行代码的拉取和信息的查看,在利用公密钥首次链接时候未绑定其机器的公钥信息, 将会导致 Host key verification failed.
解决办法: 在连接的机器上先执行git -T git@gitlab.weiyigeek.top
保存其主机的公钥信息;
# 例如 首次连接Gitlab时候需要进行主机于公钥绑定 ssh -T git@gitlab.com # 无法建立主机“gitlab.com(172.65.251.78)”的真实性。 The authenticity of host 'gitlab.com (172.65.251.78)' can\'t be established. ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw. Are you sure you want to continue connecting (yes/no/[fingerprint])?$ cat ~/.ssh/known_hosts gitlab.com,172.65.251.78 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAABFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QOLXBpQ6KWjbjTDTdDkoohFzgbEYI=
问题6.Jenkins 内置邮件通知发信测试 Failed to send out e-mail javax.mail.AuthenticationFailedException: 535 Error:
错误信息:
Failed to send out e-mail javax.mail.AuthenticationFailedException: 535 Error: ÇëʹÓÃÊÚȨÂëµÇ¼¡£ÏêÇéÇë¿´: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:947)at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:858)at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:762)at javax.mail.Service.connect(Service.java:364)
错误原因: 配置STMP的邮箱账号,输入的认证字符串是邮箱密码而并非生成的客户端密码, 在 腾讯企业邮箱、163邮箱都需要使用生成的客户端密码进行登录;
问题7.Jenkins 内置邮件通知发信测试 com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization user
错误信息:
Failed to send out e-mail com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization userat com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1817) Caused: com.sun.mail.smtp.SMTPSendFailedException: 501 mail from address must be same as authorization user ;nested exception is:com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization userat com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2374)at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1808)at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1285)at javax.mail.Transport.send0(Transport.java:231)
错误原因: 最后发现是jenkins url下面的系统管理员邮件地址没有填写或者与STMP发信邮箱不一致
解决办法: 填写系统管理员邮箱与STMP发信邮箱地址一致就可以了。
问题8.Jenkins 内置邮件通知发信测试com.sun.mail.smtp.SMTPAddressFailedException: 501 Bad address syntax
错误信息:
ERROR: Invalid Addresses javax.mail.SendFailedException: Invalid Addresses;nested exception is:com.sun.mail.smtp.SMTPAddressFailedException: 501 Bad address syntaxat com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:2064)at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1286)at javax.mail.Transport.send0(Transport.java:231)at javax.mail.Transport.send(Transport.java:100)at hudson.tasks.MailSender.run(MailSender.java:130)at hudson.tasks.MailSender.execute(MailSender.java:105)at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.cleanUp(MavenModuleSetBuild.java:1093)at hudson.model.Run.execute(Run.java:1954)at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)at hudson.model.ResourceController.execute(ResourceController.java:97)at hudson.model.Executor.run(Executor.java:429) Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 501 Bad address syntaxat com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1917)... 10 more Finished: FAILURE
错误原因: 输入的接收邮箱地址是无效的格式;
WeiyiGeek Blog - 为了能到远方,脚下的每一步都不能少。
Tips : 本文章来源 Blog 站点或者 WeiyiGeek
公众账号 (友链交换请邮我哟
):
-
微信公众号-WeiyiGeek` # 精华文章发布地址
-
https://weiyigeek.top # 采用cloudflare CDN 国内有时访问较慢
-
https://weiyigeek.gitee.io # 国内访问快可能会有更新不及时得情况
-
个人知乎-WeiyiGeek
Tips: 更多学习笔记文章请关注
WeiyiGeek
公众账号
【微信公众号关注(点击)】
【邮箱联系: Master#weiyigeek.top】
这篇关于5.Jenkins入门基础使用补充说明与相关问题总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!