Re: How to override "Shell executable" in declarative JenkinsFile

2019-08-23 Thread Giles


On Tuesday, 6 August 2019 11:01:45 UTC-4, Jérémie Faucher-Goulet wrote:
>
> 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.
>
>
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 ...

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/60db9799-9e09-4fa6-a26a-3290084db92b%40googlegroups.com.


Re: How to override "Shell executable" in declarative JenkinsFile

2019-08-22 Thread Ramanathan Muthaiah
On Tuesday, August 6, 2019 at 8:31:45 PM UTC+5:30, Jérémie Faucher-Goulet 
wrote:
>
> 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.
>
>
Not sure how this can solve your problem, but check this note here, 
https://support.cloudbees.com/hc/en-us/articles/215171038-How-do-I-run-a-different-Shell-interpreter-in-a-Pipeline-Script
 

/Ram

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/4339ab15-52bc-45a9-966b-d5d94ed2c821%40googlegroups.com.


How to override "Shell executable" in declarative JenkinsFile

2019-08-06 Thread Jérémie Faucher-Goulet
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.

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/a9d34071-aa69-4529-99a7-76994a82faf3%40googlegroups.com.