docker_jenkins_python_pytest_allure_git r囧r小猫 2022-12-23 00:34 72阅读 0赞 # 环境概述: # <table> <thead> <tr> <th>环境描述</th> <th>相关信息</th> </tr> </thead> <tbody> <tr> <td>centos</td> <td>V:7.7.1908</td> </tr> <tr> <td>centos ip</td> <td>10.227.253.230</td> </tr> <tr> <td>docker</td> <td>V:19.03.12</td> </tr> <tr> <td>jenkins</td> <td>V:2.235.5</td> </tr> <tr> <td>python</td> <td>V:3.6.5</td> </tr> <tr> <td>pytest</td> <td>V:6.0.1</td> </tr> <tr> <td>allure</td> <td>V:2.7.0</td> </tr> <tr> <td>git</td> <td>V:2.28.0</td> </tr> </tbody> </table> # docker # > docker部分学习视频:B站检索–【狂神说Java】Docker最新超详细版教程通俗易懂 **Step1:卸载docker** [root@localhost ~]# yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 **Step2:安装yum-utils** [root@localhost ~]# yum install -y yum-utils * 1 **Step3:设置镜像仓库** # 推荐阿里云 [root@localhost ~]# yum-config-manager \ --add-repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo * 1 * 2 * 3 * 4 **Step4:更新yum软件包索引** [root@localhost ~]# yum makecache fast * 1 **Step5:安装docker** # ce:社区版 / ee:企业版本 [root@localhost ~]# yum install -y docker-ce * 1 * 2 **Step6:查看docker 版本** [root@localhost ~]# docker version Client: Docker Engine - Community Version: 19.03.12 * 1 * 2 * 3 **Step7:启动docker / 加入开机启动项** [root@localhost ~]# systemctl start docker [root@localhost ~]# systemctl enable docker * 1 * 2 # docker\_jenkins # **Step1:查找jenkins镜像** [root@localhost ~]# docker search jenkins * 1 **Step2:下载jenkins/jenkins镜像** [root@localhost ~]# docker pull jenkins/jenkins:lts * 1 **Step3:查看本地镜像** [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jenkins/jenkins lts 697d76eba014 2 weeks ago 677MB * 1 * 2 * 3 **Step4:启动镜像** # -d:后台运行容器 # --name:指定容器名字 # -p:指定容器暴露的端口 host_port:container_port [root@localhost ~]# docker run -d --name jenkins8899 -p 8899:8080 jenkins/jenkins:lts c6689cb6f8b9204ea83fe84a35215123f8b0a37c3636cfe645304ffc1fc0f199 * 1 * 2 * 3 * 4 * 5 **Step5:进入到容器** # docker ps:先查看正在运行的容器 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c6689cb6f8b9 jenkins/jenkins:lts "/sbin/tini -- /usr/…" 13 hours ago Up 13 hours 50000/tcp, 0.0.0.0:8899->8080/tcp jenkins8899 # -u root:以root用户进入容器 [root@localhost ~]# docker exec -it -u root c6689cb6f8b9 /bin/bash root@f632b6ec09ec:/# * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 **Step6:获取最新的软件包并升级已安装所有软件包** # 获取最新的软件包 root@f632b6ec09ec:/# apt-get update # 升级已安装的软件包 root@f632b6ec09ec:/# apt-get upgrade # 提前安装,以便接下来的配置操作 root@f632b6ec09ec:/# apt-get install -y vim gcc make zlib* * 1 * 2 * 3 * 4 * 5 * 6 # docker\_jenkins\_allure # **Step1:下载allure** > [https://pan.baidu.com][https_pan.baidu.com] 提取码:aqsj **Step2:将allure-2.7.0.zip上传到服务器** # 将allure-2.7.0.zip上传到/usr/local/src路径下 [root@localhost ~]# cd /usr/local/src [root@localhost src]# ls -l 总用量 12072 -rw-r--r-- 1 root root 12358435 8月 25 19:43 allure-2.7.0.zip * 1 * 2 * 3 * 4 * 5 **Step3:将allure-2.7.0.zip从服务器复制到docker容器中** [root@localhost src]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c6689cb6f8b9 jenkins/jenkins:lts "/sbin/tini -- /usr/…" 18 hours ago Up 18 hours 50000/tcp, 0.0.0.0:8899->8080/tcp jenkins8899 [root@localhost src]# docker cp ./allure-2.7.0.zip jenkins8899:/usr/local/src * 1 * 2 * 3 * 4 **Step4:进入容器,解压并配置allure** # 以root用户登录到docker容器 [root@localhost ~]# docker exec -it -u root jenkins8899 /bin/bash root@f632b6ec09ec:/# cd /usr/local/src root@c6689cb6f8b9:/usr/local/src# ls -l total 12072 -rw-r--r-- 1 root root 12358435 Sep 5 15:58 allure-2.7.0.zip root@f632b6ec09ec:/usr/local/src# chmod 777 allure-2.7.0.zip root@f632b6ec09ec:/usr/local/src# unzip allure-2.7.0.zip root@f632b6ec09ec:/usr/local/src# cd allure-2.7.0 root@f632b6ec09ec:/usr/local/src/allure-2.7.0# pwd /usr/local/src/allure-2.7.0 # 该路径在jenkins配置Allure Commandline时会用到 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 # docker\_jenkins\_python3 # **Step1:安装aptitude** root@f632b6ec09ec:/# apt-get install -y aptitude * 1 **Step2:安装依赖包** root@f632b6ec09ec:/# apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget * 1 **Step3:下载python3.6.5** root@f632b6ec09ec:/# cd /usr/local/src root@f632b6ec09ec:/usr/local/src# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz * 1 * 2 **Step4:解压Python-3.6.5.tgz** root@f632b6ec09ec:/usr/local/src# ls -l total 22456 -rw-r--r-- 1 root staff 22994617 Mar 28 2018 Python-3.6.5.tgz root@f632b6ec09ec:/usr/local/src# chmod 777 Python-3.6.5.tgz root@f632b6ec09ec:/usr/local/src# tar -zxvf Python-3.6.5.tgz * 1 * 2 * 3 * 4 * 5 **Step5:执行安装** root@f632b6ec09ec:/usr/local/src# cd Python-3.6.5/ root@f632b6ec09ec:/usr/local/src/Python-3.6.5# ./configure --prefix=/usr/local/src/python36 root@f632b6ec09ec:/usr/local/src/Python-3.6.5# make && make install root@f632b6ec09ec:/usr/local/src/Python-3.6.5# chmod 777 -R ../python36/* * 1 * 2 * 3 * 4 # docker\_jenkins\_PATH # **Step1:配置python / allure环境变量** [root@localhost ~]# docker exec -it jenkins8899 /bin/bash jenkins@f632b6ec09ec:/$ cat >> ~/.bashrc << "EOF" export PATH=/usr/local/src/allure-2.7.0/bin:$PATH export PATH=/usr/local/src/python36/bin:$PATH EOF jenkins@f632b6ec09ec:/$ source ~/.bashrc jenkins@f632b6ec09ec:/$ python3 --version Python 3.6.5 jenkins@f632b6ec09ec:/$ allure --version 2.7.0 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 **Step2:安装pytest / allure-pytest** > 配置好python环境变量后,才可以使用pip3安装相关插件 # 安装pytest root@f632b6ec09ec:/$ pip3 install pytest -i http://pypi.douban.com/simple --trusted-host pypi.douban.com # 安装pytest-html root@f632b6ec09ec:/$ pip3 install pytest-html -i http://pypi.douban.com/simple --trusted-host pypi.douban.com # 安装allure-pytest 生成测试报告 root@f632b6ec09ec:/$ pip3 install allure-pytest -i http://pypi.douban.com/simple --trusted-host pypi.douban.com # 安装allure-python-commons root@f632b6ec09ec:/$ pip3 install allure-python-commons -i http://pypi.douban.com/simple --trusted-host pypi.douban.com * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 # gitLab # > 1、注册gitLab账号 > 2、创建gitLab项目 > 3、创建python代码文件:test\_错误示例.py > 4、将以下代码复制到文件中 > 5、本机安装gitLab客户端 > 6、将test\_错误示例.py上传到gitLab项目中 # coding=utf-8 def setup_module(): print('\n *** 初始化-错误模块 ***') def teardown_module(): print('\n *** 清除-错误模块 ***') class Test_错误登录(): @classmethod def setup_class(cls): cls.log.info("错误登录--类初始化") @classmethod def teardown_class(cls): cls.log.info("错误登录--类清除") def setup_method(self): self.log.info("方法初始化") def teardown_method(self): self.log.info("方法清除") def test_R001001(self): self.log.info('错误登录--用例R001001') assert 1 == 1 def test_R001002(self): self.log.info('错误登录--用例R001002') assert 2 == 2 def test_R001003(self): self.log.info('错误登录--用例R001003') assert 3 == 2 def test_R001004(self): self.log.info('错误登录--用例R001004') assert 4 == 4 * 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 # jenkins # **Step1:修改jenkins下载插件地址** root@f632b6ec09ec:/$ find -name hudson.model.UpdateCenter.xml root@f632b6ec09ec:/$ cd ./var/jenkins_home/ root@f632b6ec09ec:/$ cp hudson.model.UpdateCenter.xml hudson.model.UpdateCenter_back.xml </sites>jenkins@c6689cb6f8b9:~$ sed -i "s/https/http/g" hudson.model.UpdateCenter.xml root@c6689cb6f8b9:~$ cat hudson.model.UpdateCenter.xml <?xml version='1.1' encoding='UTF-8'?> <sites> <site> <id>default</id> <url>http://updates.jenkins.io/update-center.json</url> </site> # 退出jenkins容器 Ctrl + P + Q [root@localhost src]# docker restart jenkins8899 jenkins8899 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 **Step2:浏览器访问10.227.253.230:8899** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center] **Step3:查看jenkins管理员密码** # 在容器内,根据页面提示路径进行查询 jenkins@c6689cb6f8b9:/$ cat /var/jenkins_home/secrets/initialAdminPassword 18b7b8979f91402dbd8715feb129e240 * 1 * 2 * 3 **Step4:复制查询到的密码,并继续** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 1] **Step5:安装推荐的插件** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 2] **Step6:等待插件安装中** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 3] **Step7:创建管理员账号** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 4] **Step8:实例配置** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 5] **Step9:开始使用jenkins** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 6] **Step10:设置时间** > Manage Jenkins–> Script Console–> 输入脚本–> 运行–> 显示Result表示成功 System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai') * 1 ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 7] **Step11:上传jenkins-allure插件** > Manage Jenkins–> Manage Plugins–> Advanced–> 上传插件 > [allure-jenkins-plugin插件下载地址][allure-jenkins-plugin] ![在这里插入图片描述][20200906202801272.png_pic_center] > 安装allure-jenkins-plugin插件成功 ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 8] **Step12:配置Allure Commandline** > Manage Jenkins–> Global Tool Configuration–> Allure Commandline jenkins@c6689cb6f8b9:/$ find -name allure-2.7.0 ./usr/local/src/allure-2.7.0 # 改路径为Allure Commandline安装目录 * 1 * 2 ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 9] **Step13:创建jenkins项目** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 10] **Step14:配置源码管理** > 1、登录git > 2、选择项目 > 3、查看项目对应git的url > 4、复制url到jenkins项目的Repository URL处 ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 11] ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 12] > 添加凭证,输入用户名/密码,点击添加 ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 13] **Step15:配置构建** > /usr/local/src/python36/bin/pytest --alluredir $\{WORKSPACE\}/report ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 14] **Step16:配置构建后操作** > report ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 15] **Step17:执行立即构建** ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 16] **Step18:Allure报告** > 等待构建完成后,点击Allure Report查看测试报告 ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 17] > 以上环境结合Selenium / Appium / Reques即可成为UI / APP / 接口一整套测试框架 [https_pan.baidu.com]: https://pan.baidu.com/s/1C8BeS4-2FBdxGRSxkXnL-w [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center]: /images/20221120/a19735d3b8084d8d9f8b1cf9bd4106b2.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 1]: /images/20221120/f459e0fc205f4b83b6cc5b66466649b1.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 2]: /images/20221120/0d0ef3cadedc4cf28801975909b8436b.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 3]: /images/20221120/ef5aa86855a04d44853fbbd1cc126ccc.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 4]: /images/20221120/f1d9d8c0689a4c03a68f02d8104fee8e.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 5]: /images/20221120/bb31ffefd0e64c9a96e923cef8d80200.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 6]: /images/20221120/37d4eb7d068c4d189f837cebf566d9e5.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 7]: /images/20221120/d7167a1bb07e441f9163b31be8cc851f.png [allure-jenkins-plugin]: http://updates.jenkins-ci.org/download/plugins/allure-jenkins-plugin/2.28.1/allure-jenkins-plugin.hpi [20200906202801272.png_pic_center]: /images/20221120/d091177f60dd4b5f9ecab5145ad8b79e.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 8]: /images/20221120/73d23f0a16c0494894f3935d216b48b4.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 9]: /images/20221120/0091e0fa15a84f36bda97bddc0b98105.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 10]: /images/20221120/21b3174a4494489ea0c3ec71c1147b65.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 11]: /images/20221120/42c8bec15a534b898d49f0f472671bb8.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 12]: /images/20221120/7f563693f8f24beebe60139b91a81a2c.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 13]: /images/20221120/ea09fe64ae1b4fe082aa0cf703e92d5b.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 14]: /images/20221120/d440f4dc804a49aeb47410533055305c.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 15]: /images/20221120/cbc0f41fb41040fbbdf1fc3dbcfa88be.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 16]: /images/20221120/108deb52aca0466bb105357e62d3f4e3.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0J1TGluZ0xpbmdz_size_16_color_FFFFFF_t_70_pic_center 17]: /images/20221120/d97716a4f9dc411f85becfa8ff8d6364.png
还没有评论,来说两句吧...