How to override "Shell executable" in declarative JenkinsFile

15 views
Skip to first unread message

Jérémie Faucher-Goulet

unread,
Aug 6, 2019, 11:01:45 AM8/6/19
to Jenkins Users
Hi, I find myself in a bit of a bind and would like suggestions on how to move forward with our Jenkins cluster.

We've recently updated from a 3 year old version to start using all the beautiful pipeline plugins stuff, but would like to slowly transition our hundreds of job over time. The first part worked without too many issues and our old jobs are running fine on the updated cluster (1 master + 7 slaves). However I seem to be stuck in regards to the shell executable.

Currently, it is defined as an environment variable in our Jenkins global configuration. In this manner:
Shell executable: ${SHELL_EXEC}

Not far above, we have a default value which is defined globally, pointing to a location where we have MSYS available on most windows slaves.

Each Linux slaves override this environment variable in this manner in their node configuration:
SHELL_EXEC=/bin/sh


When I put a "sh" step in my new declarative file, I get a on a Linux node/agent:
sh: 1: ${SHELL_EXEC}: not found

I read somewhere that environment variables defined in the slave node configuration are not taken into account when using Jenkins pipeline. A pity. So I did the following tests
I tried using a environment block:
stage {    
    environment
{
        SHELL_EXEC
= '/bin/sh'
   
}
    steps
{
        sh
'echo "Something"'
   
}
}


But it doesn't work and I get the same error. I also tried using 'withEnv' this way:

stage {
    steps
{
        withEnv
(["SHELL_EXEC='/bin/sh'"]) {
            sh
'echo "This is a print test"'
       
}
   
}
}


And I also get the same error.


Does anyone have any suggestion on how to override the 'Shell executable' currently set in the global jenkins configuration? I would like to make the transition to Jenkins Pipeline as easy as possible and not having to reconfigure 100+ jobs manually just so I can blank this global setting.

Ramanathan Muthaiah

unread,
Aug 22, 2019, 11:52:26 PM8/22/19
to Jenkins Users

Giles

unread,
Aug 23, 2019, 12:27:55 PM8/23/19
to Jenkins Users
This isn't quite what you were looking for, but may be a possible solution: go into the MSYS environment and copy or link your shell of choice into /bin/sh.  If someone can tell you how to configure the shell in Jenkins as you asked, that would be better because what I'm suggesting is fragile: changes to the MSYS environment could overwrite this hackish solution.

If you were feeling aggressive about it, you could create a method in Jenkins that runs before every job and forcibly copies your shell to /bin/sh ...

Reply all
Reply to author
Forward
0 new messages