Bash and make features in Jenkins shell scripts

4,736 views
Skip to first unread message

Remi Payan

unread,
Nov 8, 2011, 9:36:38 AM11/8/11
to jenkins...@googlegroups.com

Hello,

I am a new Jenkins user currently trying to setup jobs, and I am facing two issues which I hope this group can help me resolve.

 

My Jenkins runs on a web server that connects to a slave builder via ssh.

The configuration has "/bin/bash" as shell executable.

 

Issue 1: Alias are not supported in Jenkins shell scripts (?)

 

Example

Jenkins shell:

alias myCommand='source myCommandScript.sh'

myCommand -p option

 

Job console output:

alias 'myCommand=source myCommandScript.sh'

myCommand: command not found

 

Note the location of the quote changes in the output... pointing to a parsing issue.

I have tried to place this alias in a file, which I source from the Jenkins shell, but the result is the same, myCommand is not found.

Any clue how to get this to work?

 

 

Issue 2: "make" targets using "%" syntax are not supported (?)

My build system has several nested makefiles, one of them defining a generic rule for files with defined prefix and suffix.

Example:

...

myMake%Target.c: ...

...

 

This syntax should match any target that starts with "myMake" and ends with "Target.c" (e.g. "myMakeAnyStuffTarget.c").

This works fine from a console shell, but not from Jenkins...

 

Would someone be able to comment on any of these problems?

 

Thanks in advance for your help.

 

Regards,

remp12

Ferenc Kovacs

unread,
Nov 8, 2011, 9:57:32 AM11/8/11
to jenkins...@googlegroups.com
If you are using the "Execute shell" Build task, you can have a shebang in the first line ( the ? help mentions this).
Could you try setting that to bash (I know, by the help it should use the default shell set for the user running Jenkins, but I think that there is some bug there.)?
put 
#!/bin/bash
to the first line


--
Ferenc Kovács
@Tyr43l - http://tyrael.hu

Rem

unread,
Nov 8, 2011, 3:46:03 PM11/8/11
to Jenkins Users
Hi Ferenc,
Thanks for your reply.
(I'm using a google email now because I could not log into the groups
with my other e-mail).

I was actually using a shebang already; I managed to fix the first
issue by using "shopt -s expand_aliases" (not set by default for non-
interactive shells).
The problem with the misplaced quote in the alias is still there, but
it seems to be a display issue, only in Jenkins' console output...
should probably be reported as a bug if not already done.

I'm still struggling with the second issue though, I haven't been able
to find out the root cause.
Can't figure out why "make" would behave differently in Jenkins; I
have checked all other shell options, as well as locale settings (was
suspecting LC_COLLATE env variable).
Any hint would be welcome.

Regards,
Rem


On Nov 8, 3:57 pm, Ferenc Kovacs <tyr...@gmail.com> wrote:
> On Tue, Nov 8, 2011 at 3:36 PM, Remi Payan <rem...@numericable.fr> wrote:
> > **

Sami Tikka

unread,
Nov 8, 2011, 6:44:41 PM11/8/11
to jenkins...@googlegroups.com
Jenkins does not echo the shell script lines it executes. It is the shell that does it (because of the -x option).

To debug your make problem, please find the place in the build step where you call make and before that line insert the following two lines:

env
which make

Jenkins does not affect the behavior of make in any way. Probably the environment of Jenkins is different and Jenkins is just executing a different make than you are from the command line. Usually this happens because Jenkins is running as a different user with different environment and/or Jenkins is running in a non-interactive shell, which could behave differently from an interactive shell. To find the exact way they differ, you should consult the manual of your shell.

-- Sami

Rem

unread,
Nov 9, 2011, 7:48:07 AM11/9/11
to Jenkins Users
Thanks for the hints!

I finally managed to nail down the root cause of the problem, which
lied in the makefile itself.
The target pattern had an executable command as a prerequisite, which
was used to generate the file that was matched by the target pattern.
However, in my config, this executable did not exist (was not checked
out from svn repository).

With regards to the display issue I mentionned, you were perfectly
right, it is caused by the shell and it can be easily reproduced on
the command line.
It seems to be related to spaces in the alias target, and it has
definitely nothing to do with Jenkins.

> set -x && alias test='simple test'
+ set -x
+ alias 'test=simple test'

(using GNU bash, version 3.2.25)
Reply all
Reply to author
Forward
0 new messages