1. python3.8安装
1)安装依赖项
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make
2) 安装python安装包
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
tar -zxvf Python-3.8.5.tgz
3)编译安装python
cd Python-3.8.5
mkdir /usr/local/python3.8.5
./configure --prefix=/usr/local/python3.8.5
./configure --enable-optimizations
make && make install
安装过,出现下面两行就成功了
![](https://img.haomeiwen.com/i19560005/6e0cca08530ea7d7.png)
4)创建软连接
# 查看当前python软连接
ll /usr/bin/ |grep python
系统默认安装的是2.7
删除python软连接
rm -rf /usr/bin/python
rm -rf /usr/bin/pip #删除默认pip软连接
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
查看python版本
python -V
配置软连接为python3
ln -s /usr/local/python3/bin/python3 /usr/bin/python
#添加 python 的软链接
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
#添加 pip3 的软链接
更改yum配置
vi /usr/bin/yum
把 #! /usr/bin/python 修改为 #! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
把 #! /usr/bin/python 修改为 #! /usr/bin/python2
vi /usr/bin/yum-config-manager
#!/usr/bin/python 改为 #!/usr/bin/python2
5)安装pytest
pip3 install pytest
pip3 install allure-pytest
如果遇到网络不可达
pip3 install allure-pytest -i https://pypi.mirrors.ustc.edu.cn/simple/
python3 -m pytest test.py
![](https://img.haomeiwen.com/i19560005/7b202e171f9dcef9.png)
2. Jenkins pipeline编写allure脚本
pipeline{
agent {
node {
label 'buildNode' #选择节点
}
}
stages{ // 里面可以填充多个stage
stage('Preparation') {
steps{
echo 'test'
sh "pwd"
// 此处放代码连接地址,具体操作见Jenkins pipeline片段生成章节介绍
}
}
stage('testSetProperty'){
steps{
sh "sleep 5s" //节点之间sleep睡眠
sh '(cd /home/report;python3 -m pytest test.py -s -q --alluredir ${WORKSPACE}/report/allure-results)'
//python3 -m pytest
// sh相当于开辟一个执行进程,当执行脚本是有多个步骤时,需要写到一起;pipeline执行完成之后回收进程,这时默认的根目录是job的工作目录,下个stage执行命令时需要注意
}
}
}
post('Results') { // 执行之后的操作
always{
script{// 集成allure,目录需要和保存的results保持一致,注意此处目录为job工作目录之后的目录,Jenkins会自动将根目录与path进行拼接
allure includeProperties: false, jdk: '', report: 'report/allure-report', results: [[path: 'report/allure-results']]
}
}
}
}
3.结果
![](https://img.haomeiwen.com/i19560005/13b40f40cea0b148.png)
![](https://img.haomeiwen.com/i19560005/d96db07b5ded38a1.png)
网友评论