2

DevOps实战1-jenkins的安装使用

 1 year ago
source link: http://saiya.xyz/2020/12/17/devops1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

centos7安装Jenkins

https://developer.aliyun.com/article/704929?spm=a2c6h.14164896.0.0.43a34345cQZQ1e

$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo
$ sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
$ sudo yum install -y jenkins
......

windows安装Jenkins

安装时需要验证windows系统账户和密码
这个账户需要有windows系统运行service的权限
在本地安全策略->本地策略->用户权限分配->作为服务器登录->添加用户或组
->DESKTOP-ELVIS\elvis
--from
https://blog.csdn.net/Chenftli/article/details/108487494

实例配置
Jenkins URL:
http://localhost:10240/
Jenkins URL 用于给各种Jenkins资源提供绝对路径链接的根地址。 这意味着对于很多Jenkins特色是需要正确设置的,例如:邮件通知、PR状态更新以及提供给构建步骤的BUILD_URL环境变量。

推荐的默认值显示在尚未保存,如果可能的话这是根据当前请求生成的。 最佳实践是要设置这个值,用户可能会需要用到。这将会避免在分享或者查看链接时的困惑。

Red Hat/CentOS

出现报错:

Public key for jenkins-xxxx.rpm is not installed

使用如下命令导入验证key

rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

启动jenkins出现问题

jenkins】# systemctl start jenkins.service

报错:
Mar 17 12:18:15 iZbp13os69edbi58q9yr87Z systemd[1]: Starting LSB: Jenkins Automation Server...
Mar 17 12:18:15 iZbp13os69edbi58q9yr87Z runuser[12627]: pam_unix(runuser:session): session opened for user root by (uid=0)
Mar 17 12:18:15 iZbp13os69edbi58q9yr87Z jenkins[12622]: Starting Jenkins bash: /usr/bin/java: No such file or directory
Mar 17 12:18:15 iZbp13os69edbi58q9yr87Z jenkins[12622]: [FAILED]
Mar 17 12:18:15 iZbp13os69edbi58q9yr87Z systemd[1]: jenkins.service: control process exited, code=exited status=1
Mar 17 12:18:15 iZbp13os69edbi58q9yr87Z systemd[1]: Failed to start LSB: Jenkins Automation Server.
Mar 17 12:18:15 iZbp13os69edbi58q9yr87Z systemd[1]: Unit jenkins.service entered failed state.
Mar 17 12:18:15 iZbp13os69edbi58q9yr87Z systemd[1]: jenkins.service failed.
原因是没有Java路径

jenkins】#which Java
/root/soft/jdk1.8.0_101/bin/java

jenkins】#vi /etc/rc.d/init.d/jenkins
找到 candidates ="/etc/...
/usr/.....
/usr/.......
/usr/.....
.........."
引号里面结果插入 /root/soft/jdk1.8.0_101/bin/java

Jenkins】#systemctl daemon-reload
jenkins】#service jenkins start

$ systemctl enable jenkins # 开机启动
$ systemctl start jenkins # 启动jenkins

查看初始密码

查看密码
jenkins】#cat /var/lib/jenkins/secrets/initialAdminPassword

需要在gitee或者gitlab有提交时,通过webhook触发jenkins构建。

此时涉及到了跨域问题

高版本无法通过系统全局安全设置关闭跨域检测。

service jenkins restart

高版本jenkins不能界面禁用跨站请求伪造保护。

高版本禁用跨站请求伪造保护操作如下:

修改jenkins的配置文件。vim /etc/sysconfig/jenkins

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true"

配置后重启jenkins。 service jenkins restart (一定要重启)

码云和jenkins的联动

https://gitee.com/help/articles/4193#article-header11

jenkins和钉钉的联动

构建成功或失败时发送钉钉通知

  1. jenkins安装DingTalk和Dingding json pusher两个插件
  2. 在系统设置中设置钉钉机器人的webhook等。
  3. 在工程的设置中需要a)勾选钉钉机器人b)构建完成后的动作

https://oapi.dingtalk.com/robot/send?access_token=c03b4deddc81fac76fd3b142axxxxxxxxxxxxxx

https://blog.csdn.net/xu990128638/article/details/106643585

https://www.cnblogs.com/jassa/p/12504214.html

https://blog.csdn.net/weixin_40874592/article/details/81458041


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK