I met a problem with jenkins novadays which I barely figure out what the problem is. It was very strange and I very encounter a term named Shebang which is mostly at the first line of a script which can be runnable on shell. You will get what I mean via that example;
#!/usr/bin/python # this is the shebang
print 'Hello world'
The problem about shebang is, there is a character length limit. If you exceed the limit, the script can't be run. This limit was 128 characters for my Ubuntu16.04
machine, but I saw some other limits like 64 etc. So this limit may be different for your machines.
This limit is enough for your local or your production environemnts but, it may be problem on some systems like CI tools. Because, every build, new unique workspace path will be used. Because of need of unique workspace, CI tools might keep the path very long like my Jenkins
did. Because of my Jenkins
keeps the workapce path longer than before somehow, the pip
script in the virtual environment created by tox
couldn't be run. It was something like;
#!/var/lib/jenkins/workspace/bird-enki_dev-WU5CNL6OW2YOPXESKE6ETDGYY6FX2ZRNOECJUDKDACFRMOSF3JKA/TOXENV/test/.tox/test/bin/python3.5
I had never encountered that problem before, because somehow my unique workpsace paths didn't exceed the limit. So the problem was hard to detect for me. When I detect the problem, I saw some solutions doesn't works. I didn't want to touch a kernel parameter named BINPRM_BUF_SIZE
to increase that weird shebang character lenght limit. I try to use jenkins plugin named Short Workspace Plugin. It makes the workapce path shorter though, I couldn't make it works. Actually I don't even understand what this plugin does exactly.
Anyway, I found the solution on modifying tox workdir
parameter as outside of the workspace created by jenkins. Hence, the shebang line can be shorter. Thanks to tox support something like workdir
and I could decide for another path. You can define it on "tox running" like;
tox --wordir /your/path
or in your tox.ini
file which I prefer. I will share the part of my tox.ini
;
[tox]
envlist =test,cov,errors
[tox:jenkins]
toxworkdir={homedir}/.tox-{env:JOB_NAME}
JOB_NAME
variable is from jenkins itself. So, the tox folder will be in like;
/home/jenkins_user/.tox-my-project/
That's it, you have shorter shebang
now and the problem is solved.