@@ -73,7 +73,7 @@ class BuildCommand(BuildCommandResultMixin):
73
73
74
74
def __init__ (self , command , cwd = None , shell = False , environment = None ,
75
75
combine_output = True , input_data = None , build_env = None ,
76
- bin_path = None , description = None ):
76
+ bin_path = None , description = None , record_as_success = False ):
77
77
self .command = command
78
78
self .shell = shell
79
79
if cwd is None :
@@ -96,6 +96,7 @@ def __init__(self, command, cwd=None, shell=False, environment=None,
96
96
self .description = ''
97
97
if description is not None :
98
98
self .description = description
99
+ self .record_as_success = record_as_success
99
100
self .exit_code = None
100
101
101
102
def __str__ (self ):
@@ -183,12 +184,21 @@ def get_command(self):
183
184
184
185
def save (self ):
185
186
"""Save this command and result via the API."""
187
+ exit_code = self .exit_code
188
+
189
+ # Force record this command as success to avoid Build reporting errors
190
+ # on commands that are just for checking purposes and do not interferes
191
+ # in the Build
192
+ if self .record_as_success :
193
+ log .warning ('Recording command exit_code as success' )
194
+ exit_code = 0
195
+
186
196
data = {
187
197
'build' : self .build_env .build .get ('id' ),
188
198
'command' : self .get_command (),
189
199
'description' : self .description ,
190
200
'output' : self .output ,
191
- 'exit_code' : self . exit_code ,
201
+ 'exit_code' : exit_code ,
192
202
'start_time' : self .start_time ,
193
203
'end_time' : self .end_time ,
194
204
}
@@ -300,8 +310,8 @@ def run(self, *cmd, **kwargs):
300
310
return self .run_command_class (cls = self .command_class , cmd = cmd , ** kwargs )
301
311
302
312
def run_command_class (
303
- self , cls , cmd , record = None , warn_only = False , force_success = False ,
304
- ** kwargs ):
313
+ self , cls , cmd , record = None , warn_only = False ,
314
+ record_as_success = False , ** kwargs ):
305
315
"""
306
316
Run command from this environment.
307
317
@@ -310,16 +320,22 @@ def run_command_class(
310
320
:param record: whether or not to record this particular command
311
321
(``False`` implies ``warn_only=True``)
312
322
:param warn_only: don't raise an exception on command failure
313
- :param force_success : force command ``exit_code`` to be saved as ``0``
314
- (``True`` implies ``warn_only=True``)
323
+ :param record_as_success : force command ``exit_code`` to be saved as
324
+ ``0`` (``True`` implies ``warn_only=True`` and ``record =True``)
315
325
"""
316
326
if record is None :
317
327
# ``self.record`` only exists when called from ``*BuildEnvironment``
318
328
record = getattr (self , 'record' , False )
319
329
320
- if not record or force_success :
330
+ if not record :
321
331
warn_only = True
322
332
333
+ if record_as_success :
334
+ record = True
335
+ warn_only = True
336
+ # ``record_as_success`` is needed to instantiate the BuildCommand
337
+ kwargs .update ({'record_as_success' : record_as_success })
338
+
323
339
# Remove PATH from env, and set it to bin_path if it isn't passed in
324
340
env_path = self .environment .pop ('BIN_PATH' , None )
325
341
if 'bin_path' not in kwargs and env_path :
@@ -340,10 +356,6 @@ def run_command_class(
340
356
self .record_command (build_cmd )
341
357
342
358
if build_cmd .failed :
343
- if force_success :
344
- self ._log_warning ('Forcing command to exit gracefully (exit_code = 0)' )
345
- build_cmd .exit_code = 0
346
-
347
359
msg = u'Command {cmd} failed' .format (cmd = build_cmd .get_command ())
348
360
349
361
if build_cmd .output :
@@ -445,8 +457,7 @@ def handle_exception(self, exc_type, exc_value, _):
445
457
return True
446
458
447
459
def record_command (self , command ):
448
- if self .record :
449
- command .save ()
460
+ command .save ()
450
461
451
462
def _log_warning (self , msg ):
452
463
# :'(
0 commit comments