Jenkins 2.7 - How to list all files in a directory

1,059 views
Skip to first unread message

Kristian

unread,
May 30, 2016, 1:43:56 PM5/30/16
to jenkins...@googlegroups.com
Hello all,

I have a problem. In a job of Jenkins, I want to iterate over a bunch
of files, e.g. *.c. This is done through a shell script for Linux,
e.g.

for f in $(ls *.c); do
echo "$f"
done

That is how it is written in the job. But when I start, Jenkins changes it into

++ ls '*.c'
ls: cannot access *.c: No such file or directory

As you can see, Jenkins changes the command
> ls *.c
into
> ls '*.c'

Is this a bug? Are there any workarounds?

Baptiste Mathus

unread,
May 30, 2016, 5:32:23 PM5/30/16
to jenkins...@googlegroups.com
Add #!/bin/bash as first line. 


--
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/CAO5HUhPE_c%2B85phWiCmeTyEeAGxmLJ%2BJ8vVef3epbvXvVNe1kw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Beck

unread,
May 31, 2016, 5:38:36 AM5/31/16
to jenkins...@googlegroups.com

> On 30.05.2016, at 19:43, Kristian <kristian...@gmail.com> wrote:
>
> Is this a bug? Are there any workarounds?

Looks like there are no such files and then the shell does not glob. Look for 'nullglob' in `man bash`.

Daniel Beck

unread,
May 31, 2016, 6:54:43 AM5/31/16
to jenkins...@googlegroups.com

> On 30.05.2016, at 19:43, Kristian <kristian...@gmail.com> wrote:
>
> for f in $(ls *.c); do

Also, this is wrong. `for f in *.c` does the same thing, but has fewer bugs (spaces in file names etc.)

Reply all
Reply to author
Forward
0 new messages