前言python自動(dòng)化的腳本開發(fā)完成后需提交到git代碼倉庫,接下來就是用Jenkins拉取代碼去構(gòu)建自動(dòng)化代碼了 git源碼管理代碼上傳git倉庫這里就不介紹了,可以看之前寫過的github相關(guān)這篇https://www.cnblogs.com/yoyoketang/p/7302515.html 自己公司內(nèi)部的一般用gitlab,可以參考這篇https://www.cnblogs.com/yoyoketang/p/10282529.html 打開Jenkins新建一個(gè)自由風(fēng)格的項(xiàng)目 源碼管理Repository URL 代碼倉庫地址 備注:如果是ssh方式鏈接的,就點(diǎn)右上角的SSH地址 Credentials 點(diǎn)開Jenkins按鈕,輸入git倉庫登陸的賬號和密碼 構(gòu)建 執(zhí)行shell執(zhí)行shell,先pip3安裝requirements.txt,再用pytest執(zhí)行腳本 查看控制臺輸入出,console查看日志 + ls requirements.txt test_demo.py + pip3 install -r requirements.txt Collecting requests==2.18.4 (from -r requirements.txt (line 1)) Downloading
Installing collected packages: idna, urllib3, requests, atomicwrites, six, more-itertools, wcwidth, attrs, py, zipp, importlib-metadata, pluggy, pytest, pytest-metadata, pytest-html Found existing installation: idna 2.8 Uninstalling idna-2.8: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/var/jenkins_home/python3/lib/python3.6/site-packages/idna-2.8.dist-info/INSTALLER' Consider using the `--user` option or check the permissions. 發(fā)現(xiàn)沒有權(quán)限安裝,可以進(jìn)入容器內(nèi)部安裝 docker exec -it -u root 容器id /bin/bash
打開workspace目錄安裝 /home/jenkins/workspace/pytest_demo [root@cb8e397d5308]# cd /home/jenkins/workspace/pytest_demo [root@cb8e397d5308]# ls requirements.txt test_demo.py [root@cb8e397d5308]# pip3 install -r requirements.txt 安裝完成后輸入pytest檢查pytest:-bash: pytest: command not found [root@VM_0_2_centos pytest_demo]# pytest -bash: pytest: command not found 查找pytest安裝地址添加軟鏈接,輸入pytest —version查看環(huán)境 [root@cb8e397d5308]# find / -name pytest /var/jenkins_home/python3/bin/pytest [root@cb8e397d5308]# ln -s /var/jenkins_home/python3/bin/pytest /usr/bin/pytest [root@cb8e397d5308]# pytest --version This is pytest version 4.5.0, imported from /root/python36/lib/python3.6/site-packages/pytest.py setuptools registered plugins: pytest-html-1.19.0 at /root/python36/lib/python3.6/site-packages/pytest_html/plugin.py pytest-metadata-1.8.0 at /root/python36/lib/python3.6/site-packages/pytest_metadata/plugin.py 構(gòu)建上面需要的環(huán)境都安裝完成后,執(zhí)行shell的時(shí)候,直接輸入pytest命令就可以執(zhí)行自動(dòng)化的腳本了 構(gòu)建成功
|