Jenkins Pipeline Job sthrowing Error code 126 when trying to execute a sh command

2,479 views
Skip to first unread message

Mike Chmielewski

unread,
Jun 20, 2016, 2:21:07 PM6/20/16
to Jenkins Users
Hi all!

I have been banging my head on this for a while, and now hope the greater community can help me out. I am starting out with workflows, and almost immediately hit a snag.

I have the following setup:

Jenkins 2.7 on:

- CentOS 6.7 master
- CentOS 7.1 on agents

- Pipeline 2.1

I have the following script:

node ('agent_label') {
    stage 'echo'
    echo 'Hello!'
    
    println env.getEnvironment()
    
    stage 'sh'
    sh 'echo hello sh!'
}

When I run this job manually, the job errors out on:

sh 'echo hello sh!'

With the following error:

[t1] Running shell script
sh
: <PATH_TO_AGENT_WORKSPACE_ROOT>/t1@tmp/durable-ae020333/script.sh: bash: bad interpreter: No such file or directory

Looking in the directory listed the t1@tmp/ directory is empty. This error happens with the Groovy Sandbox setting set to true or false.

Running a freestyle job with a shell script works without issue. Has anyone seen this and possibly even resolved this?

Thanks!

Eric Pyle

unread,
Jun 20, 2016, 2:32:26 PM6/20/16
to jenkins...@googlegroups.com

I've been struggling with this same issue. It only seems to be a problem on Linux - Windows slaves work OK. One theory I have is that it could be related to the "Shell executable" setting in the main configuration page (Manage Jenkins->Configure System). I have the shell executable set as "bash". Do you have the same?

Eric

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fa080423-5ce6-4b10-8749-1126fccd8c4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Craig Rodrigues

unread,
Jun 20, 2016, 2:34:30 PM6/20/16
to Jenkins Users
Hi,

When you use sh in a Pipeline, and you need to debug weird things,
then you need to look at the source code of the Durable Task plugin to figure out what is going on,
because that is what is executing the underlying shell.  Specifically, look at this:

https://github.com/jenkinsci/durable-task-plugin/blob/master/src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java#L98

It's a bit hard to figure out what is going on in your environment, but one question I have is.....do you have bash installed on your system,
and if so, where is it?

If you can somehow save a copy of the  durable-ae020333/script.sh

that would help debug things.

--
Craig

Slide

unread,
Jun 20, 2016, 2:59:35 PM6/20/16
to Jenkins Users
You could try changing your sh invocation to something like the following:

sh """\
#!/bin/sh
echo hello sh!
"""

This would force the interpreter to use whatever is setup as sh in your environment. I believe sh uses bash by default, but if you don't have it installed, that would be a problem.



--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Mike Chmielewski

unread,
Jun 20, 2016, 3:25:51 PM6/20/16
to Jenkins Users
Eric, I do! I will try making that explicit and let the thread know what the situation.

Craig, I've tried, but I can't seem to catch it, the job dies in less than half a second.

slide, I do have bash installed, as freestyle jobs run just fine, and the SHELL env variable on the slave is set to a valid bash executable location.

Mike Chmielewski

unread,
Jun 20, 2016, 3:27:26 PM6/20/16
to Jenkins Users
Eric, I removed the "bash" and left the setting blank, and my job worked! Thanks for the lead!

Craig Rodrigues

unread,
Jun 21, 2016, 9:47:47 AM6/21/16
to Jenkins Users
To debug the problem, would you be comforable modifying and rebuilding the Durable Task plugin?
You could temporarily comment out the code that removes the script.sh and see what is going on.

I had to do that before to debug problems with the durable task plugin.

--
Craig


On Mon, Jun 20, 2016 at 12:25 PM, Mike Chmielewski <mike.chm...@gmail.com> wrote:

Craig, I've tried, but I can't seem to catch it, the job dies in less than half a second.

[t1] Running shell script sh: <PATH_TO_AGENT_WORKSPACE_ROOT>/t1@tmp/durable-ae020333/script.sh: bash: bad interpreter: No such file or directory

Looking in the directory listed the t1@tmp/ directory is empty. This error happens with the Groovy Sandbox setting set to true or false.

Running a freestyle job with a shell script works without issue. Has anyone seen this and possibly even resolved this?

Thanks!
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fa080423-5ce6-4b10-8749-1126fccd8c4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Mike Chmielewski

unread,
Jun 21, 2016, 10:59:05 PM6/21/16
to Jenkins Users, rod...@freebsd.org
The issue seems to have been jenkins filling in the empty default shell in the global configuration when moving to Jenkins 2.X. Removing it made it all work.
Reply all
Reply to author
Forward
0 new messages