让Jenkins可以使用python脚本 环境:前篇的用docker安装Jenkins

1:Jenkins支持python环境

参考文章:https://www.cnblogs.com/yoyoketang/p/12116246.html

1-1:进jenkins容器

进docker容器, 加上-u root 以root用户权限进入容器 docker exec -it -u root 容器id /bin/bash

1-2:容器内部安装python3环境

下载python3安装包 进入容器内部, linux安装python3环境,参考这篇https://www.cnblogs.com/yoyoketang/p/10195102.html

  1. root@cb8e397d5308:/var/jenkins_home# cd /var/jenkins_home/
  2. root@cb8e397d5308:/var/jenkins_home# mkdir python3
  3. root@cb8e397d5308:/var/jenkins_home# cd python3/
  4. root@cb8e397d5308:/var/jenkins_home/python3# wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
  5. root@cb8e397d5308:/var/jenkins_home/python3# tar -xvf Python-3.8.2.tgz
  6. root@cb8e397d5308:/var/jenkins_home/python3# cd Python-3.8.2
  7. root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# ./configure --prefix=/var/jenkins_home/python3
  8. checking build system type... x86_64-pc-linux-gnu
  9. checking host system type... x86_64-pc-linux-gnu
  10. checking for python3.6... no
  11. checking for python3... no
  12. checking for python... python
  13. checking for --enable-universalsdk... no
  14. checking for --with-universal-archs... no
  15. checking MACHDEP... linux
  16. configure: error: in `/var/jenkins_home/python3/Python-3.6.8':
  17. configure: error: no acceptable C compiler found in $PATH
  18. See `config.log' for more details

1-3:报错了需要安装编译环境(no acceptable C compiler found in $PATH
你可以选择一个个安:

apt-get -y install gcc automake autoconf libtool make apt-get -y install make apt-get -y install zlib apt-get -y install openssl libssl-dev apt-getinstall sudo

也可以直接安装这个:

linuxidc@linuxidc:~/www.linuxidc.com$ sudo apt install build-essential 该命令将安装一堆新包,包括gcc,g ++和make

附带更新国内源:【当时在这个项目上我是没换,你可以你看看换不换】

https://blog.csdn.net/qq_35451572/article/details/79516563

1-4:make编译安装

  1. ./configure --prefix=/var/jenkins_home/python3 --with-ssl
  2. make
  3. make install

如果在make install的时候报错zipimport.ZipImportError: can’t decompress data; zlib not available

从错误信息分析,就是缺少了zlib的解压缩类库,安装即可 apt-y install zlib* 安装完成之后,重新安装即可,所有的问题都已经正常解决了

1-5:添加软链接
添加python3软链接

ln -s /var/jenkins_home/python3/bin/python3.8 /usr/bin/python ln -s /var/jenkins_home/python3/bin/python3.8 /usr/bin/python3.8

添加pip3软链接

ln -s /var/jenkins_home/python3/bin/pip3 /usr/bin/pip3

1-6:检查环境
输入pip3 和python3检查环境

root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# pip3 root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# python3 Python 3.6.8 (default, Jan 1 2020, 10:15:14) [GCC 6.3.0 20170516] on linux Type “help”, “copyright”, “credits” or “license” for more information. >>> exit()

使用pip3安装一个requests包

pip3 install requests

好了你已经正确安装了环境了!!!

2:Jenkins安装python插件

2-1:安装python插件
image.png
2-2:去编写脚本:

image.png
image.pngimage.png