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、手動構建工程,結果顯示正確,點擊可以查看報告。
在這裏插入圖片描述

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