Jenkins bulid get an error message: java.io.IOException: error=7, Argument list too long

What’s  occured?

When Jenkins triggered a  build job defines as “Free-Style Project”, a build failed with this error message


[starfish-verify-drd] $ /bin/bash /tmp/jenkins8550337881106633559.sh

FATAL: command execution failed

java.io.IOException: error=7, Argument list too long

	at java.lang.UNIXProcess.forkAndExec(Native Method)

	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)

	at java.lang.ProcessImpl.start(ProcessImpl.java:134)

	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to swfarm-gateuobld17

		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1737)

		at hudson.remoting.UserResponse.retrieve(UserRequest.java:313)

		at hudson.remoting.Channel.call(Channel.java:952)

		at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1052)

		at hudson.Launcher$ProcStarter.start(Launcher.java:449)

		at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)

		at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)

		at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)

		at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)

		at hudson.model.Build$BuildExecution.build(Build.java:206)

		at hudson.model.Build$BuildExecution.doRun(Build.java:163)

		at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)

		at hudson.model.Run.execute(Run.java:1727)

		at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)

		at hudson.model.ResourceController.execute(ResourceController.java:97)

		at hudson.model.Executor.run(Executor.java:429)

Caused: java.io.IOException: Cannot run program "/bin/bash" (in directory "/vol/users/gatekeeper.tvsw/cerberus_root/starfish-verify-drd"): error=7, Argument list too long

	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

Cause 

  • One argument must not be longer than MAX_ARG_STRLEN (131072 bytes)

Reference

Advertisements

Jenkins: Make an agent connection to EC2 instance.

Conditions

  • EC2 instance has no Elastic IP.
  • When an agent has been in idle status for some times, that instance has to be stopped.

Script

#!/bin/bash
set -x
export PATH=/vol/users/gatekeeper.tvsw/.local/bin:$PATH
ID=${1}
echo "INFO: Jenkins Url = ${JENKINS_URL}" >&2
echo "INFO: Start EC2 instance - ${ID}" >&2
aws ec2 start-instances --instance-ids ${ID} >&2

echo "INFO: Wait until EC2 ${ID} will be 'Running'" >&2
aws ec2 wait instance-running --instance-ids ${ID} >&2

echo "INFO: Wait for 10 seconds" >&2
sleep 10
echo "INFO: Get ${ID}s PublicIpAddress" >&2
IP=`aws ec2 describe-instances --instance-ids ${ID}|grep PublicIpAddress |sed 's/\ //g'|sed 's/\"//g'|sed 's/\,//g'|awk -F: '{print $2}'`
NETWORKIFID=`aws ec2 describe-instances --instance-ids ${ID}|grep NetworkInterfaceId|sed 's/\ //g'|sed 's/\"//g'|sed 's/\,//g'|awk -F: '{print $2}'`
echo "INFO: ${ID}s PublicIpAddress = ${IP}" >&2
echo "INFO: ${ID}s NetworkInterfaceId= ${NETWORKIFID}" >&2

trap term_action SIGTERM
function term_action() {
echo "INFO: Stop an instance: ${ID}" >&2
aws ec2 stop-instances --instance-ids ${ID} 2>/dev/null
>&2 echo "INFO: Stopped:${ID}"
}

date >&2
rm -rf slave.jar
wget --auth-no-challenge --no-check-certificate ${JENKINS_URL}/jnlpJars/slave.jar
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null slave.jar ubuntu@${IP}:~/slave.jar >&2
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -n ubuntu@${IP} 'ls -al ~/slave.jar' >&2
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -n ubuntu@${IP} mk_disk_i3 >&2
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -n ubuntu@${IP} mkdir -p ${WORKSPACE} >&2
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -n ubuntu@${IP} 'echo Postech2001! | sudo -b openconnect --juniper svlvpn.lge.com -u allessunjoo.park --passwd-on-stdin >> ~/.openconnect_watchdog.log 2>&1 &'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@${IP} 'java -jar ~/slave.jar'
term_action
set +x

Configuration on Jenkins

Jenkins Github Plugin Configurations

  1. Install GitHub Plugin
  2. Go to https://github.com/settings/tokens and Click ‘Generate new token’
    Screen Shot 2017-07-21 at 2.54.40 PM
    Screen Shot 2017-07-21 at 2.55.40 PM.png
  3. On Jenkins Site, Go to ‘Manage Jenkins’ > ‘Configure System’ > ‘GitHub section
  4. Select ‘Add GitHub Server > GitHub Server’
    Screen Shot 2017-07-21 at 2.59.55 PM.png
  5. Click ‘Credentials > Add Jenkins’ and Write a generated token from GitHub with additional information
    • Domain: Global credentials
    • Kind: Secret text
    • Scope: Global
    • Secret: Generated token value
    • ID: Distinct text for this credential
      Screen Shot 2017-07-21 at 3.02.06 PM.png
  6. Select a credential you created and Click ‘Test Connection’
    Screen Shot 2017-07-21 at 3.13.35 PM.png
  7. Go to a build job configuration and Change configuration
    • Source Code Management
      Screen Shot 2017-07-21 at 3.35.37 PM.png
    • Build Trigger
      Screen Shot 2017-07-21 at 3.35.51 PM.png