前言
使用docker安装jenkins环境,jenkins构建的workspace目录默认是在容器里面构建的,如果我们想执行python3的代码,需进容器内安装python3的环境;
进jenkins容器
进docker容器,加上 -u root 以root用户权限进入容器
docker exec -it -u root 容器name /bin/bash
查看当前操作系统 cat /etc/issue;
root@86723e0cd5bb:/# uname -a Linux 86723e0cd5bb 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64 GNU/Linux root@86723e0cd5bb:/# cat /etc/issue Debian GNU/Linux 9 l
这里查到的是Debian系统(不是ubuntu,也不是centos),这里yum是没有的,所以不能用yum安装了,这里用apt-get代替yum
先执行更新apt-get
apt-get update
容器内部安装python3环境
下载python3安装包
进入容器内容,linux安装python3环境
root@cb8e397d5308:/var/jenkins_home# cd /var/jenkins_home/ root@cb8e397d5308:/var/jenkins_home# mkdir python3 root@cb8e397d5308:/var/jenkins_home# cd python3/ root@cb8e397d5308:/var/jenkins_home/python3# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz root@cb8e397d5308:/var/jenkins_home/python3# tar -xvf Python-3.6.8.tgz root@cb8e397d5308:/var/jenkins_home/python3# ls Python-3.6.8 Python-3.6.8.tgz root@cb8e397d5308:/var/jenkins_home/python3# cd Python-3.6.8 root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# ./configure --prefix=/var/jenkins_home/python3 checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python3.6... no checking for python3... no checking for python... python checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... linux checking for --without-gcc... no checking for --with-icc... no checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/var/jenkins_home/python3/Python-3.6.8': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
执行 ./configure --prefix=/var/jenkins_home/python3
时报上面错:configure: error: no acceptable C compiler found in $PATH
apt-get 安装依赖包
这个是因为缺少gcc相关依赖包,使用apt-get代替yum安装相关依赖包
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-get install sudo
make编译安装
在/var/jenkins_home/python3/Python-3.6.8目录下执行make和make install安装
./configure --prefix=/var/jenkins_home/python3 --with-ssl make make install
注意:上面加--with--ssl参数,此时不加该参数,后面pip安装可以报ssl相关问题;
添加软链接
添加python3软链接
ln -s /var/jenkins_home/python3/bin/python3.6 /usr/bin/python3
添加pip3软链接
ln -s /var/jenkins_home/python3/bin/pip3 /usr/bin/pip3
检查环境
输入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