1.docker安装Jenkins
pytest -docker安装Jenkins--配置节点
拉取镜像
[root@localhost ~]# docker pull jenkins
Using default tag: latest
latest: Pulling from library/jenkins
55cbf04beb70: Pull complete
1607093a898c: Pull complete
9a8ea045c926: Pull complete
d4eee24d4dac: Pull complete
c58988e753d7: Pull complete
794a04897db9: Pull complete
70fcfa476f73: Pull complete
0539c80a02be: Pull complete
54fefc6dcf80: Pull complete
911bc90e47a8: Pull complete
38430d93efed: Pull complete
7e46ccda148a: Pull complete
c0cbcb5ac747: Pull complete
35ade7a86a8e: Pull complete
aa433a6a56b1: Pull complete
841c1dd38d62: Pull complete
b865dcb08714: Pull complete
5a3779030005: Pull complete
12b47c68955c: Pull complete
1322ea3e7bfd: Pull complete
Digest: sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668
Status: Downloaded newer image for jenkins:latest
docker.io/library/jenkins:latest
启动容器
现在,就可以基于下载的镜像运行 Jenkins 容器了,有以下两种运行方式供你参考:
方式一:直接运行,运行期间产生的所有数据都保存在容器内部,容器销毁,数据丢失。
docker run \
--name jenkins\
-d \
-p 8080:8080 \
-p 50001:50000 \
jenkins
方式二:Docker 会在宿主机上创建一个数据卷jenkins-data,容器映射该卷以持久化数据。
docker run \
--name jenkins \
-d \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins-home:/var/jenkins_home \
jenkinsci/blueocean
Tips:8080 端口用来公开访问 Web 界面,50000 端口允许访问远程 Java (JIRA) API。
这里我使用了第二种方式启动了 一个 Jenkins 容器应用:
[root@localhost ~]# docker run \
> --name jenkins \
> -d \
> -p 8080:8080 \
> -p 50000:50000 \
> -v /opt/jenkins-home:/var/jenkins_home \
> jenkinsci/blueocean
f3e7127d2257acfa26fd211fed6ddd257667992193caf0f7494ec20d3c65fe1b
docker run --name jenkins -d -p 8080:8080 -p 50000:50000 -v /opt/jenkins-home:/var/jenkins_home --rm jenkinsci/blueocean
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f3e7127d2257 jenkins "/bin/tini -- /usr/l…" 8 minutes ago Up 8 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:50000->50000/tcp, :::50000->50000/tcp jenkins
Jenkins启动
/var/jenkins_home/secrets/initialAdminPassword
管理员初始密码被放到了/var/jenkins_home/secrets/initialAdminPassword 文件中。
因为我们把 Jenkins 部署在了 Docker 容器中,因此需要先进入到容器,再去查看对应的文件initialAdminPassword内容:
step1:进入容器获取密码
[root@localhost jenkins-home]# docker exec -it jenkins /bin/bash
jenkins@953b7308ae19:/$ cat /var/jenkins_home/secrets/initialAdminPassword
cc065b696d4c47f9b2341eeab02fda3c
cc065b696d4c47f9b2341eeab02fda3c
[root@localhost ~]# docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
3c8a660892fd40eba8a69526a8f6e3c7
[root@localhost ~]#
step2:安装插件
http://192.168.222.128:8080/
点击建议安装的插件
Jenkins配置
Jenkins配置节点
-
1、点击管理Jenkins,系统配置,管理节点
-
2、点击新节点
-
3、输入节点名称,点击固定节点,点击ok
-
4、电脑任意路径新建一个文件夹作为远程工作目录
D:\jenkins-workspace -
5、配置节点
其中,有如下几点需要注意:
【# of executors】根据CPU的个数来填写数量
【远程工作目录】这个就是用来存放master到slave时,存放的临时目录,如slave的服务软件也会放在此,并且会以每个job名称来区分开
【用法】只需要选择【只允许运行绑定到这台机器的Job】这种模式下,Jenkins只会构建哪些分配到这台机器的Job。这允许一个节点专门保留给某种类型的Job。例如,在Jenkins上连续的执行测试,你可以设置执行者数量为1,那么同一时间就只会有一个构建,一个实行者不会阻止其它构建,其它构建会在另外的节点运行。
【启动方式】只需要选择【Launch agent via Java Web Start】,以服务的方式启动,应用最广且最好配置,其余的都太复杂,不建议使用
- 6、点击节点进入,点击下载agent.jar包,最好跟你的工作目录同级,方便查找
- 7、在agent目录启动cmd命令行,复制命令粘贴到命令行中,直到connected
节点显示在线
allure配置
Jenkins插件管理中查找allure,并安装
全局工具中配置allure
构建后操作中配置allure执行路径
邮箱配置
发件人邮箱设置--密码是邮箱的授权码
收件人邮箱设置
安装插件:editable email notification
构建后操作
参考配置:
https://www.cnblogs.com/gcgc/p/5631385.html
问题记录
-
1、An error occurred during installation: No such plugin: cloudbees-folder
- 原因:很明显,就是没有上面提示这个插件导致。
- 解决:解决三步走
- 第一步:跳过推荐插件安装界面
- 直接访问, 默认:http:// IP:8080/restart
- 第二步:手动下载插件
- 访问 【清华大学开源软件镜像站】 提供的镜像下载此插件
地址: https://mirrors.tuna.tsinghua.edu.cn/jenkins/plugins/cloudbees-folder/
- 访问 【清华大学开源软件镜像站】 提供的镜像下载此插件
- 第三步:将下载的cloudbees-folder.hpi文件上传到 /var/jenkins_home/plugins目录下
- 重启Jenkins即可!
- 第一步:跳过推荐插件安装界面
-
2、Jenkins容器docker run之后状态总是Exited
- 原因:查看docker日志 :
docker logs jenkins
发现是目前权限问题
因为/opt/jenkins-home 目录是root权限
- 原因:查看docker日志 :
[root@localhost jenkins-home]# docker logs jenkins
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
drwxr-xr-x 2 root root 6 7月 24 09:24 jenkins-home
改变权限
drwxr-xr-x 3 1000 1000 58 7月 24 09:58 jenkins-home
-
解决方案:chown -R 1000:1000 /opt/jenkins-home //用户组改变
-
3、
[root@localhost opt]# docker logs jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Jul 24, 2021 2:05:17 AM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at Main._main(Main.java:293)
at Main.main(Main.java:132)
Caused by: java.lang.IllegalArgumentException: Unrecognized option: --rm
at winstone.cmdline.CmdLineParser.parse(CmdLineParser.java:53)
at winstone.Launcher.getArgsFromCommandLine(Launcher.java:359)
at winstone.Launcher.main(Launcher.java:332)
... 6 more- 原因:docker 命令顺序不正确
- 方案:docke run 命令格式:docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
-
4、Jenkins使用官方的版本,提示太高,不支持安装插件
[root@localhost ~]# docker search jenkins
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jenkins Official Jenkins Docker image 5250 [OK]
jenkins/jenkins The leading open source automation server 2599
jenkinsci/blueocean https://jenkins.io/projects/blueocean 629
jenkinsci/jenkins Jenkins Continuous Integration and Delivery … 390
jenkins/jnlp-slave a Jenkins agent which can connect to Jenkins… 146 [OK]
jenkinsci/jnlp-slave A Jenkins slave using JNLP to establish conn… 133 [OK]
jenkinsci/slave Base Jenkins slave docker image 67 [OK]
jenkins/slave base image for a Jenkins Agent, which includ… 47 [OK]
jenkinsci/ssh-slave A Jenkins SSH Slave docker image 44 [OK]
jenkins/ssh-slave A Jenkins slave using SSH to establish conne… 37 [OK]
cloudbees/jenkins-enterprise CloudBees Jenkins Enterprise (Rolling releas… 34 [OK]
h1kkan/jenkins-docker 🤖 Extended Jenkins docker image, bundled wi… 29
xmartlabs/jenkins-android Jenkins image for Android development. 28 [OK]
openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use w… 23
cloudbees/jenkins-operations-center CloudBees Jenkins Operation Center (Rolling … 14 [OK]
jenkins/ssh-agent Docker image for Jenkins agents connected ov… 11
vfarcic/jenkins-swarm-agent Jenkins agent based on the Swarm plugin 8 [OK]
openshift/jenkins-slave-base-centos7 A Jenkins slave base image. DEPRECATED: see … 7
trion/jenkins-docker-client Jenkins CI server with docker client 6 [OK]
publicisworldwide/jenkins-slave Jenkins Slave based on Oracle Linux 5 [OK]
openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima… 4
ansibleplaybookbundle/jenkins-apb An APB which deploys Jenkins CI 1 [OK]
mashape/jenkins Just a jenkins image with the AWS cli added … 0 [OK]
amazeeio/jenkins-slave A jenkins slave that connects to a master vi… 0 [OK]
jameseckersall/jenkins docker-jenkins (based on openshift jenkins 2… 0 [OK]
根据镜像OFFICIAL标签判断,位列第一、名字为jenkins的是 Jenkins 官方提供的镜像。我们是不是应该使用这个官方镜像呢?
如果你看过 Jenkins 文档中 Docker 安装 小节,会发现官方推荐使用的镜像是jenkinsci/blueocean,该镜像包含当前的长期支持 (LTS) 的 Jenkins 版本 (可以生产使用) ,并捆绑了所有 Blue Ocean 插件和功能。
- 解决方法:重新安装回jenkinsci/blueocean
[root@localhost ~]# docker run --name jenkins -d -p 8080:8080 -p 50000:50000 -v /opt/jenkins-home:/var/jenkins_home --rm jenkinsci/blueocean
63b27b21bc78f634055e390811a60e091d98e0e1732f08379b77a243cb8503c4
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63b27b21bc78 jenkinsci/blueocean "/sbin/tini -- /usr/…" About a minute ago Up About a minute 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:50000->50000/tcp, :::50000->50000/tcp jenkins
- 5、Jenkins界面展示为英文
- 解决:
- 一、解决方法:到插件管理中安装插件Localization: Chinese (Simplified),这个其实就已经够的了,初次安装只需要重启一下jenkins服务即可,在重启登录界面就正常显示中文的了
- 解决: