I have a build with a text parameters in Jenkins, when I input big data into text area and try to build, it comes
[TEST-save_txt_to_file] $ /bin/sh -xe /tmp/hudson3834163952953567847.sh FATAL: command execution failed java.io.IOException: Cannot run program "/bin/sh" (in directory "/var/lib/jenkins/workspace/TEST-save_txt_to_file"): java.io.IOException: error=7, Argument list too long at java.lang.ProcessBuilder.start(Unknown Source) at hudson.Proc$LocalProc.(Proc.java:244) at hudson.Proc$LocalProc.(Proc.java:216) at hudson.Launcher$LocalLauncher.launch(Launcher.java:763) at hudson.Launcher$ProcStarter.start(Launcher.java:353) at hudson.Launcher$ProcStarter.join(Launcher.java:360) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:91) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:60) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:814) at hudson.model.Build$BuildExecution.build(Build.java:199) at hudson.model.Build$BuildExecution.doRun(Build.java:160) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:593) at hudson.model.Run.execute(Run.java:1568) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:237) Caused by: java.io.IOException: java.io.IOException: error=7, Argument list too long at java.lang.UNIXProcess.(Unknown Source) at java.lang.ProcessImpl.start(Unknown Source) ... 17 more Build step 'Execute shell' marked build as failure Finished: FAILURE
Is there any workaround? Thanks!
my ENV:
java.runtime.version 1.6.0_41-b02
org.jenkins-ci.main:jenkins-war:1.502
Best Answer
This is caused by a linux limitation whereby the arguments can't exceed 128kb in size See Linux Kernel constant: MAX_ARG_STRLEN https://github.com/torvalds/linux/blob/master/include/uapi/linux/binfmts.h
Within Jenkins once you read from/to a variable where this value is exceeded, you will hit this error. In my case, I had a github webhook that launched a Jenkins job and set a payload parameter to some string > than this limit. Attempting to read this parameter would throw this error.
In order to work around the problem, I have a child job that uses a rest-api call to read the value from parent
You can let the parent job throw a failure, but allow the child job to be launched in all cases. Below is a slightly refined function I used to pull the information (Stripped out error checking and comments for brevity)