@@ -82,6 +82,7 @@ public function configure()
8282
8383 $ this ->addArgument ('target ' , InputArgument::OPTIONAL , 'Target to build ' , null );
8484 $ this ->addOption ('nodeps ' , 'D ' , InputOption::VALUE_NONE , 'Ignore dependencies ' );
85+ $ this ->addOption ('keep-exit-code ' , '-k ' , InputOption::VALUE_NONE , 'Keep the exit code of a job if it fails ' );
8586 }
8687
8788 /**
@@ -114,17 +115,20 @@ public function execute(InputInterface $input, OutputInterface $output)
114115 if (!$ this ->question ->ask ($ input , $ output , $ question )) {
115116 $ this ->output ->writeln ('Bye! ' );
116117
117- return ;
118+ return 0 ;
118119 }
119120 }
120121
121122 $ this ->output ->writeln ('' );
122- $ this ->runBuilders ($ builders );
123+ $ exitCode = $ this ->runBuilders ($ builders );
123124
124125 $ end = microtime (true );
125126
126127 $ this ->output ->writeln (sprintf ('<info>Done (%ss)</info> ' , number_format ($ end - $ start , 2 )));
127128
129+ if ($ exitCode !== 0 && $ input ->getOption ('keep-exit-code ' )) {
130+ return $ exitCode ;
131+ }
128132 return 0 ;
129133 }
130134
@@ -172,6 +176,7 @@ protected function runBuilders($builders)
172176
173177 $ builderContext = new BuilderContext ($ this ->input , $ this ->output , $ this ->getApplication ());
174178
179+ $ combinedExitCode = 0 ;
175180 foreach ($ builders as $ builder ) {
176181 $ this ->output ->getFormatter ()->setIndentLevel (0 );
177182
@@ -187,8 +192,13 @@ protected function runBuilders($builders)
187192 $ this ->output ->writeln ('' );
188193
189194 $ this ->output ->getFormatter ()->setIndentLevel (1 );
190- $ builder ->build ();
195+ $ exitCode = $ builder ->build ();
196+ if ($ exitCode !== null && $ exitCode !== 0 ) {
197+ $ combinedExitCode = $ exitCode ;
198+ }
191199 }
200+
201+ return $ combinedExitCode ;
192202 }
193203
194204 protected function writeTitle ($ title )
0 commit comments