I have 完后还有通过 Jenkins 声明性管道运行 Docker 的权限问题。我想通过 Docker 容器中的 Jenkins 作业构建和发布 Python 包:
pipeline {
agent {
docker {
image 'python:3.7'
label 'docker && linux'
}
}
environment {
PACKAGE_VERSION = readFile 'VERSION'
}
stages {
stage('Package') {
steps {
sh 'python -V'
sh 'python -m pip install -r requirements.txt --user --no-cache'
sh 'python setup.py sdist'
}
}
stage('Deploy') {
steps {
...
}
}
}
post {
always {
cleanWs()
}
}
}
但是,我不被允许pip install
由于一个PermissionError
:
+python -m pip install -rrequirements.txt --user --no-cache 要求已满足:setuptools in
/usr/local/lib/python3.7/site-packages (来自 -rrequirements.txt (行
1)) (40.0.0) 收集 pytest(来自 -rrequirements.txt(第 2 行))
正在下载https://files.pythonhosted.org/packages/9e/a1/8166a56ce9d89fdd9efcae5601e71758029d90e5644e0b7b6eda07e67c35/pytest-3.7.0-py2.py3-none-any.whl https://files.pythonhosted.org/packages/9e/a1/8166a56ce9d89fdd9efcae5601e71758029d90e5644e0b7b6eda07e67c35/pytest-3.7.0-py2.py3-none-any.whl(202kB) 收集 py>=1.5.0 (来自 pytest->-rrequirements.txt (行
2)) 下载https://files.pythonhosted.org/packages/f3/bd/83369ff2dee18f22f27d16b78dd651e8939825af5f8b0b83c38729069962/py-1.5.4-py2.py3-none-any.whl https://files.pythonhosted.org/packages/f3/bd/83369ff2dee18f22f27d16b78dd651e8939825af5f8b0b83c38729069962/py-1.5.4-py2.py3-none-any.whl(83kB) 收集 more-itertools>=4.0.0 (来自 pytest->-r
requirements.txt(第2行))正在下载https://files.pythonhosted.org/packages/79/b1/eace304ef66bd7d3d8b2f78cc374b73ca03bc53664d78151e9df3b3996cc/more_itertools-4.3.0-py3-none-any.whl https://files.pythonhosted.org/packages/79/b1/eace304ef66bd7d3d8b2f78cc374b73ca03bc53664d78151e9df3b3996cc/more_itertools-4.3.0-py3-none-any.whl(48kB)收集pluggy>=0.7(来自pytest->-rrequirements.txt(行
2)) 下载https://files.pythonhosted.org/packages/f5/f1/5a93c118663896d83f7bcbfb7f657ce1d0c0d617e6b4a443a53abcc658ca/pluggy-0.7.1-py2.py3-none-any.whl https://files.pythonhosted.org/packages/f5/f1/5a93c118663896d83f7bcbfb7f657ce1d0c0d617e6b4a443a53abcc658ca/pluggy-0.7.1-py2.py3-none-any.whl收集六个>=1.10.0(来自 pytest->-rrequirements.txt(第2行))
正在下载https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl收集atomicwrites>=1.0(来自pytest->-rrequirements.txt(行
2)) 下载https://files.pythonhosted.org/packages/0a/e8/cd6375e7a59664eeea9e1c77a766eeac0fc3083bb958c2b41ec46b95f29c/atomicwrites-1.1.5-py2.py3-none-any.whl https://files.pythonhosted.org/packages/0a/e8/cd6375e7a59664eeea9e1c77a766eeac0fc3083bb958c2b41ec46b95f29c/atomicwrites-1.1.5-py2.py3-none-any.whl收集 attrs>=17.4.0(来自 pytest->-rrequirements.txt(第 2 行))
正在下载https://files.pythonhosted.org/packages/41/59/cedf87e91ed541be7957c501a92102f9cc6363c623a7666d69d51c78ac5b/attrs-18.1.0-py2.py3-none-any.whl https://files.pythonhosted.org/packages/41/59/cedf87e91ed541be7957c501a92102f9cc6363c623a7666d69d51c78ac5b/attrs-18.1.0-py2.py3-none-any.whl安装收集的软件包:py、6、more-itertools、pluggy、
原子写入、属性、pytest
由于环境错误而无法安装软件包:[Errno 13] 权限被拒绝:'/.local'
检查权限。
如何修复这些权限?
我发现了我自己认为更漂亮的解决方案:
stage("Python Test") {
agent {
docker {
label "docker && linux"
image "python:3.7"
}
}
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
sh "pip install -r requirements.txt --user"
# python stuff
}
}
post {
cleanup {
cleanWs()
}
}
}
此解决方法完全解决了问题本身,在用户级别安装软件包。这里的问题是 HOME 目录最初也是不可写的,因此会覆盖 HOME 目录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)