running shell commands in pipeline fails on pushd and source

322 views
Skip to first unread message

Carsten

unread,
Dec 7, 2018, 8:36:33 AM12/7/18
to Jenkins Users
Hi list,

in a jenkinsfile I trigger a bash script like so:
"...
myresult=sh(script: 'deploy.sh', returnStdout: true)
..."
the script starts but returns errors like these:

"command not found: pushd"
"command not found: source"

And for some reasons it is not able to do such things:
"...
targetmachine=(
'host1'
'host2'
'host3'
)
..."

it replies: Syntax error: "(" unexpected.

Other commands like "if", "for", "echo", a.s.o are working.

The script itself is tested on the machine, where jenkins is running, and it works.
Jenkins is installed as docker image "docker pull jenkins:jenkins".
The Image is started as "root" using "sudo docker run...."
Does anybody have an idea why these commands and the array creation fails?

br
Carsten 

Mark Waite

unread,
Dec 7, 2018, 9:52:47 AM12/7/18
to Jenkins Users
That seems to hint that the shell invoked on that agent by the Pipeline script is not compatible with the shell syntax you're using.

For example, is the shell on that agent inadvertently configured to be 'dash' instead of 'bash'?  Is it configured to be 'csh' instead of 'bash'?

https://askubuntu.com/questions/590899/how-to-check-which-shell-am-i-using suggests that you might run a test job with an sh 'echo $0' or with sh 'echo $SHELL'

--
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/a2181b6e-96cc-4182-abca-a8ae0a0e195f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Thanks!
Mark Waite

Carsten

unread,
Dec 10, 2018, 11:00:45 AM12/10/18
to Jenkins Users
Hi,
It was a "SHELL"-Engine issue indeed.
I changed the call to this:

"...
myresult=sh(script: 'bash deploy.sh', returnStdout: true)
..."

and everything works fine, now.

Thanks for the hint.
br
Carsten
Reply all
Reply to author
Forward
0 new messages