0

I've written a shell-script to build all projects mentioned in a particular file using a while loop and gradle clean build command to do so.

Here is how it looks like:

echo -e "\Building all projects"
filename="projects"      #File Containing all projects name to build
workdir=$(pwd)
while read -r line; do
    name="$line"
    echo -e "\ngradle build repo - $name"
    cd $workdir/$name
    gradle clean build 
done < "$filename"

Here is contents of projects file:

core
dal
dao
web
ui

and here is my directory structure

src
|-script.sh
|-core
|  |-build.gradle
|  |-gradle.properties
|  |-src
|  |-otherstuff
|
|-dal
|  |-build.gradle
|  |-gradle.properties
|  |-src
|  |-otherstuff
|
|-dao
|  |-build.gradle
|  |-gradle.properties
|  |-src
|  |-otherstuff
|
|-same repeats for web and ui

So I expect my script to read file projects and go into all the mentioned folders from that file and issue command gradle clean build in that folder.

Everything works fine and as expected except gradle command no matter whether build succeeds or fails for the first project (core) it makes script to break the loop and exit.

So It prints output only for the first project and doesn't work for all other.

However,

If I try to run it in the background it works fine; ie; instead of

gradle clean build

if I issue

gradle clean build &

It works fine; Although output, in that case, is gibberish.

Can anyone please look into this and help me out??

Thanks in advance.

6
  • Have you thought about doing this the other way around? stackoverflow.com/questions/25562207/… Commented Mar 20, 2019 at 8:13
  • try forcing the return value of gradle to success: gradle clean build || true; however, most build system try to do it the other way round: stop early when a built-error appears... Commented Mar 20, 2019 at 8:31
  • @umläute, Already tried it; also tried to catch return value in if but with no luck :( . Also even if the gradle build runs without any error still it stops after the first iteration itself.. Don't know what is happening internally. Commented Mar 20, 2019 at 10:01
  • try gradle --console plain clean build & disown Commented Mar 20, 2019 at 10:36
  • 2
    Thanks @tripleee, issuing gradle --console plain clean build </dev/null solved my issue :) ! Commented Mar 25, 2019 at 9:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.