Linux环境下Jenkins+robotframework持续集成

安装启动jenkins

1、先安装并配置jdk

ubuntu@VM-0-5-ubuntu:~$ java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)

2、下载Jenkins包
下载地址:http://mirrors.jenkins-ci.org/
版本选择:最新的war包
在这里插入图片描述
3、将war包上传到Linux服务器,并启动
启动命令:nohup java -jar jenkins.war --httpPort=8080 &

nohup command & 的意思是在后台永久运行

ubuntu@VM-0-5-ubuntu:~/jk$ rz
rz waiting to receive.
ubuntu@VM-0-5-ubuntu:~/jk$ ls
jenkins.war
ubuntu@VM-0-5-ubuntu:~/jk$ nohup java -jar jenkins.war --httpPort=8080 &
[1] 29394
ubuntu@VM-0-5-ubuntu:~/jk$ nohup: ignoring input and appending output to 'nohup.out'

4、在浏览器输入 http://服务器IP:8080/ 打开如下页面表示启动成功
在这里插入图片描述

5、打开服务器存储密码的文件,使用密码登录

cat /home/ubuntu/.jenkins/secrets/initialAdminPassword

略过所有操作,先来到首页再说
在这里插入图片描述

安装插件

1、进入插件管理页面,点击Advanced
在这里插入图片描述
2、在页面底部设置Update Site,然后点击 submit
http://mirror.xmission.com/jenkins/updates/update-center.json在这里插入图片描述
3、重启Jenkins
重启命令不生效,使用浏览器输入http://IP:8080/restart

4、进入插件管理,选择自己想要插件安装即可
在这里插入图片描述
更多插件内容,建议查看官网 https://plugins.jenkins.io/

在Linux服务器安装robot

1、服务器默认安装了python 2.7

ubuntu@VM-0-5-ubuntu:~$ python -V
Python 2.7.15+

2、安装pip
sudo apt install python-pip

ubuntu@VM-0-5-ubuntu:~$ sudo apt install python-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libexpat1 libexpat1-dev libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev libpython2.7-minimal libpython2.7-stdlib
  python-all python-all-dev python-crypto python-dbus python-dev python-gi python-keyring python-keyrings.alt python-pip-whl
  python-secretstorage python-wheel python-xdg python2.7 python2.7-dev python2.7-minimal
Suggested packages:
  python-crypto-doc python-dbus-dbg python-dbus-doc python-gi-cairo gnome-keyring libkf5wallet-bin gir1.2-gnomekeyring-1.0 python-fs
  python-gdata python-keyczar python-secretstorage-doc python2.7-doc binfmt-support
The following NEW packages will be installed:
  libexpat1-dev libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev python-all python-all-dev python-crypto python-dbus
  python-dev python-gi python-keyring python-keyrings.alt python-pip python-pip-whl python-secretstorage python-wheel python-xdg
  python2.7-dev

3、安装robot
sudo pip install robotframework

ubuntu@VM-0-5-ubuntu:~$ sudo pip install robotframework
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting robotframework
  Downloading http://mirrors.tencentyun.com/pypi/packages/22/0f/1b9ffa0c4e59789b50e6034866e823b7d4a5c7eaedad7bfd0bba42f2aa9d/robotframework-3.1.2-py2.py3-none-any.whl (602kB)
    100% |████████████████████████████████| 604kB 3.4MB/s 
Installing collected packages: robotframework
Successfully installed robotframework-3.1.2

4、安装requests包
pip install requests


ubuntu@VM-0-5-ubuntu:~$ pip install requests
Collecting requests
  Downloading http://mirrors.tencentyun.com/pypi/packages/1a/70/1935c770cb3be6e3a8b78ced23d7e0f3b187f5cbfab4749523ed65d7c9b1/requests-2.23.0-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 662kB/s 
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
  Downloading http://mirrors.tencentyun.com/pypi/packages/e8/74/6e4f91745020f967d09332bb2b8b9b10090957334692eb88ea4afe91b77f/urllib3-1.25.8-py2.py3-none-any.whl (125kB)
    100% |████████████████████████████████| 133kB 1.1MB/s 
Collecting chardet<4,>=3.0.2 (from requests)
  Downloading http://mirrors.tencentyun.com/pypi/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 3.1MB/s 
Collecting certifi>=2017.4.17 (from requests)
  Downloading http://mirrors.tencentyun.com/pypi/packages/b9/63/df50cac98ea0d5b006c55a399c3bf1db9da7b5a24de7890bc9cfd5dd9e99/certifi-2019.11.28-py2.py3-none-any.whl (156kB)
    100% |████████████████████████████████| 163kB 3.1MB/s 
Collecting idna<3,>=2.5 (from requests)
  Downloading http://mirrors.tencentyun.com/pypi/packages/89/e3/afebe61c546d18fb1709a61bee788254b40e736cff7271c7de5de2dc4128/idna-2.9-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 56.3MB/s 
Installing collected packages: urllib3, chardet, certifi, idna, requests
Successfully installed certifi-2019.11.28 chardet-3.0.4 idna-2.9 requests-2.23.0 urllib3-1.25.8


5、将写好的脚本上传到Linux服务器
6、执行脚本报错pybot: command not found
执行命令:pybot -d 执行结果保存地址 robot用例文件

ubuntu@VM-0-5-ubuntu:~/rf/tracyTest/suite1$ pybot -d  /home/ubuntu/rf/tracyTest/results  /home/ubuntu/rf/tracyTest/suite1/suite1.robot
pybot: command not found

sudo pip uninstall robotframework卸载robot
sudo pip install robotframework==3.0安装3.0版本后再次执行
运行结果如下:

ubuntu@VM-0-5-ubuntu:~/rf/tracyTest/common$ pybot -d  /home/ubuntu/rf/tracyTest/results  /home/ubuntu/rf/tracyTest/suite1/suite1.robot
==============================================================================
Suite1                                                                        
==============================================================================
case                                                                  | PASS |
------------------------------------------------------------------------------
case2                                                                 | PASS |
------------------------------------------------------------------------------
case3                                                                 | PASS |
------------------------------------------------------------------------------
44444444444                                                           | PASS |
------------------------------------------------------------------------------
Suite1                                                                | PASS |
4 critical tests, 4 passed, 0 failed
4 tests total, 4 passed, 0 failed
==============================================================================
Output:  /home/ubuntu/rf/tracyTest/results/output.xml
Log:     /home/ubuntu/rf/tracyTest/results/log.html
Report:  /home/ubuntu/rf/tracyTest/results/report.html

Jenkins运行robotframework脚本

1、安装robotframework插件
在这里插入图片描述
如果安装失败可以到官网下载,手动安装
https://plugins.jenkins.io/robot/

2、安装完插件记得一定要重启Jenkins
3、新建一个自由风格的软件项目
在这里插入图片描述
4、源码管理设置“无”,触发器设置为每天执行
在这里插入图片描述
5、设置构建命令

pybot -d  /home/ubuntu/rf/tracyTest/results  /home/ubuntu/rf/tracyTest/suite1/suite1.robot

在这里插入图片描述
6、设置运行结果保存文件
在这里插入图片描述
7、手动构建工程,结果显示正确,点击可以查看报告。
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章