docker_jenkins_python_pytest_allure_git

Environmental overview:

Environment description Related Information
centos V : 7.7.1908
centos ip 10.227.253.230
docker V : 03/19/12
jenkins V : 2.235.5
python V : 3.6.5
pytest V : 6.0.1
allure V : 2.7.0
git V : 2.28.0

docker

Docker part of the learning video: B site search-[Mad God said Java] Docker latest super detailed version of the tutorial is easy to understand

Step1: uninstall 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: Install yum-utils

[root@localhost ~]# yum install -y yum-utils
  • 1

Step3: Set up the mirror warehouse

# 推荐阿里云
[root@localhost ~]# yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 1
  • 2
  • 3
  • 4

Step4: Update yum package index

[root@localhost ~]# yum makecache fast
  • 1

Step5: install docker

# ce:社区版 / ee:企业版本
[root@localhost ~]# yum install -y docker-ce
  • 1
  • 2

Step6: Check the docker version

[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.12
  • 1
  • 2
  • 3

Step7: Start docker / add startup items

[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
  • 1
  • 2

docker_jenkins

Step1: Find the jenkins mirror

[root@localhost ~]# docker search jenkins
  • 1

Step2: Download the jenkins/jenkins mirror

[root@localhost ~]# docker pull jenkins/jenkins:lts
  • 1

Step3: View the local mirror

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jenkins/jenkins     lts                 697d76eba014        2 weeks ago         677MB
  • 1
  • 2
  • 3

Step4: Start the mirror

# -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: Enter the container

# 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: Get the latest software package and upgrade all installed packages

# 获取最新的软件包
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: Download allure

https://pan.baidu.com extraction code: aqsj

Step2: Upload allure-2.7.0.zip to the server

# 将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: Copy allure-2.7.0.zip from the server to the docker container

[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: Enter the container, unzip and configure 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: Install aptitude

root@f632b6ec09ec:/# apt-get install -y aptitude
  • 1

Step2: Install dependent packages

root@f632b6ec09ec:/#  apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
  • 1

Step3: Download 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: Unzip 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: Perform installation

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: Configure python / allure environment variables

[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: Install pytest / allure-pytest

After configuring the python environment variables, you can use pip3 to install related plug-ins

# 安装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. Register a gitLab account
2. Create a gitLab project
3. Create a python code file: test_error example.py
4. Copy the following code to the file
5. Install the gitLab client on the machine
6. Upload test_error example.py Into the gitLab project

# 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: Modify the jenkins download plug-in address

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: Browser visit 10.227.253.230:8899
Insert picture description here
Step3: View the jenkins administrator password

# 在容器内,根据页面提示路径进行查询
jenkins@c6689cb6f8b9:/$ cat /var/jenkins_home/secrets/initialAdminPassword
18b7b8979f91402dbd8715feb129e240
  • 1
  • 2
  • 3

Step4: Copy the queried password and continue
Insert picture description here
Step5: Install the recommended plug-in
Insert picture description here
Step6: Wait for the plug-in installation
Insert picture description here
Step7: Create an administrator account
Insert picture description here
Step8: Example configuration

Insert picture description here
Step9: Start using jenkins

Insert picture description here
Step10: Set the time

Manage Jenkins–> Script Console–> Enter script–> Run–> Show Result to indicate success

System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai')
  • 1

Insert picture description here
Step11: Upload the jenkins-allure plugin

Manage Jenkins–> Manage Plugins–> Advanced–> upload plug-in
allure-jenkins-plugin plug-in download address

Insert picture description here

Successfully installed allure-jenkins-plugin

Insert picture description here
Step12: Configure 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

Insert picture description here

Step13: Create a jenkins project
Insert picture description here
Step14: Configure source code management

1. Log in to git
2. Select the project
3. View the url of the project corresponding to git
4. Copy the url to the repository URL of the jenkins project

Insert picture description here

Insert picture description here

Add credentials, enter username/password, click add

Insert picture description here

Step15: Configuration build

/usr/local/src/python36/bin/pytest --alluredir ${WORKSPACE}/report

Insert picture description here
Step16: Configure post-build operations

report

Insert picture description here
Step17: Execute immediate construction Step18
Insert picture description here
: Allure report

After the build is completed, click Allure Report to view the test report

Insert picture description here

The above environment combined with Selenium / Appium / Reques can become a set of UI / APP / interface testing framework

Guess you like

Origin blog.csdn.net/chuancheng_zeng/article/details/109864298