2025年jenkins拉取gitlab代码_python 获取jenkins的构建信息

jenkins拉取gitlab代码_python 获取jenkins的构建信息前言 python 自动化的脚本开发完成后需提交到 git 代码仓库 接下来就是用 Jenkins 拉取代码去构建自动化代码了 新建项目 打开 Jenkins 新建一个自由风格的项目 源码管理 Repository URL 代码仓库地址 Credentials git 仓库登陆的账号和密码凭证 指定分支 为空时代表 any 分支默认 master 构建 shell 脚本 执行 shell

前言

python自动化的脚本开发完成后需提交到git代码仓库,接下来就是用Jenkins拉取代码去构建自动化代码了

新建项目

打开Jenkins新建一个自由风格的项目

源码管理

Repository URL 代码仓库地址

Credentials git仓库登陆的账号和密码凭证

指定分支(为空时代表any)分支默认*/master

构建shell脚本

执行shell,先pip3安装requirements.txt,再用pytest执行脚本


查看控制台输入出,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.7/site-packages/idna-2.8.dist-info/INSTALLER'
Consider using the `--user` option or check the permissions.

发现没有权限安装,可以进入容器内部安装

docker exec -it -u root 容器id /bin/bash

打开workspace目录安装 /home/jenkins/workspace/apitest_demo

[root@3be4b6cd9b8c]# cd /home/jenkins/workspace/apitest_demo
[root@3be4b6cd9b8c]# ls
requirements.txt test_demo.py
[root@3be4b6cd9b8c]# pip3 install -r requirements.txt
安装完成后输入pytest检查pytest:-bash: pytest: command not found

查找pytest安装地址添加软链接,输入pytest –version查看环境

[root@3be4b6cd9b8c]# find / -name pytest
/var/jenkins_home/python3/bin/pytest
[root@3be4b6cd9b8c]# ln -s /var/jenkins_home/python3/bin/pytest /usr/bin/pytest
[root@3be4b6cd9b8c]# pytest --version
pytest 6.2.1

构建job

上面需要的环境都安装完成后,执行shell的时候,直接输入pytest命令就可以执行自动化的脚本了

构建成功

编程小号
上一篇 2025-02-16 12:21
下一篇 2025-02-24 19:11

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/130090.html