我正在尝试设置一个在Docker容器中运行tox
的Jenkins管道。有一个已知的问题,在 Jenkins (Jenkins)和two solutions are proposed中,shebang行变得很长。第一种是使用--workdir
选择较短的路径。此选项原则上有效,但是我从Jenkins松开了每个项目的自动唯一路径名。因此,我宁愿使用第二个选项TOX_LIMITED_SHEBANG
。不幸的是,当应该安装要测试的软件包时,似乎会出现以下错误:FileNotFoundError: [Errno 2] No such file or directory: "b'/bin/sh'": "b'/bin/sh'"
。我已验证/bin/sh
实际上在docker容器中可用。 Jenkinsfile如下所示:
node("docker") {
// burnpanck/tox-base contains tox and many python versions
docker.image('burnpanck/tox-base').inside {
checkout scm
stage('Matrix-test using Tox') {
// verify that /bin/sh exists
sh 'ls -al /bin'
// the following does not work
sh 'TOX_LIMITED_SHEBANG=1 tox -vv'
// the following works
// sh 'tox --workdir=/var/jenkins_home/tox'
}
}
}
Tox是3.1.2版,可在python 3.6下运行(docker镜像是从此Dockerfile生成的)。使我感到惊讶的是来自
str
的“b'/ bin / sh'”-设置了bytes
实例。可能是tox实际上正在尝试在路径sh'
中使用名称b'/bin
运行程序吗?使用中的
tox.ini
只是调用pytest
:[tox]
envlist = py36
[testenv]
recreate = True
commands =
pytest
来自tox的完整回溯(Jenkins控制台输出)如下:
py36 create: /var/jenkins_home/workspace/_debug_jenkins-long-shebang-L7UHBNCVPSOBSTKZ7COPFJBJLWR5XZXFIAD7TBGC4WQLVDLZYVQQ/.tox/py36
py36 inst: /var/jenkins_home/workspace/_debug_jenkins-long-shebang-L7UHBNCVPSOBSTKZ7COPFJBJLWR5XZXFIAD7TBGC4WQLVDLZYVQQ/.tox/dist/test_model-0.dev20180717.zip
ERROR: invocation failed (errno 2), args: [b'/bin/sh', '/var/jenkins_home/workspace/_debug_jenkins-long-shebang-L7UHBNCVPSOBSTKZ7COPFJBJLWR5XZXFIAD7TBGC4WQLVDLZYVQQ/.tox/py36/bin/pip', 'install', '/var/jenkins_home/workspace/_debug_jenkins-long-shebang-L7UHBNCVPSOBSTKZ7COPFJBJLWR5XZXFIAD7TBGC4WQLVDLZYVQQ/.tox/dist/test_model-0.dev20180717.zip'], cwd: /var/jenkins_home/workspace/_debug_jenkins-long-shebang-L7UHBNCVPSOBSTKZ7COPFJBJLWR5XZXFIAD7TBGC4WQLVDLZYVQQ
Traceback (most recent call last):
File "/.pyenv/versions/3.6.6/bin/tox", line 11, in <module>
sys.exit(cmdline())
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/session.py", line 39, in cmdline
main(args)
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/session.py", line 45, in main
retcode = Session(config).runcommand()
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/session.py", line 422, in runcommand
return self.subcommand_test()
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/session.py", line 620, in subcommand_test
self.installpkg(venv, path)
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/session.py", line 561, in installpkg
venv.installpkg(path, action)
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/venv.py", line 277, in installpkg
self._install([sdistpath], extraopts=extraopts, action=action)
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/venv.py", line 342, in _install
self.run_install_command(packages=packages, options=options, action=action)
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/venv.py", line 314, in run_install_command
redirect=self.session.report.verbosity < 2,
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/venv.py", line 427, in _pcall
return action.popen(args, cwd=cwd, env=env, redirect=redirect, ignore_ret=ignore_ret)
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/session.py", line 153, in popen
popen = self._popen(args, cwd, env=env, stdout=stdout, stderr=subprocess.STDOUT)
File "/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tox/session.py", line 248, in _popen
env=env,
File "/.pyenv/versions/3.6.6/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/.pyenv/versions/3.6.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: "b'/bin/sh'": "b'/bin/sh'"
最佳答案
我们目前有an open bug。当tox在python3下运行时,TOX_LIMITED_SHEBANG
损坏。
根本原因是缺少.decode()
,列表最终混合了bytes
和str
实例。
直到I fix it的变通办法是将tox与python2解释器一起使用或不使用TOX_LIMITED_SHEBANG
。
关于python - 在docker内Jenkins的tox中找不到`/bin/sh`,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51580617/