Bulk size text parameters in jenkins report error

Jenkins

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)

def get_parameter_value_from_parent():
    host = 'https://[YOUR_COMPANY].ci.cloudbees.com'
    this_build_url = os.environ.get('BUILD_URL')
    request_auth = (JENKINS_USER, JENKINS_TOKEN)

    url = '{0}/api/json'.format(this_build_url)
    parameter_name = 'payload'
    payload = ''

    #
    # Get the upstreamBuild number, and the upstreamUrl
    # so we can put together a link to the upstream job
    #

    response = requests.get(url, auth=request_auth)
    this_build = json.loads(response)

    build_number = ''
    short_url = ''
    actions = this_build['actions']
    for action in actions:
        if action.get('causes'):
            for cause in action.get('causes'):
                build_number = cause['upstreamBuild']
                short_url = cause['upstreamUrl']

    parent_url = '{host}/{short_url}{build}/api/json'.format(host=host,
            short_url=short_url, build=build_number)

    #
    # Now get the payload from the parent job by making REST api call
    #

    response = requests.get(parent_url, auth=request_auth)
    upstream_build = json.loads(response)

    actions = upstream_build['actions']
    for action in actions:
        if action.get('parameters'):
            for parameter in action.get('parameters'):
                if parameter['name'] == parameter_name:
                    value = parameter['value']
                    payload = value
                    return payload

    print 'Error: Unable to return payload from parent jenkins job: {0}'.format(parent_url)
    sys.exit(1)
Related Topic