def execute(self, context): """Perform the plugin's task purpose.""" for condition in self._conditions: expr = BooleanExpression(condition) if expr.evaluate(context): return Result(result='continue') return Result(result='success')
def execute(self, context): """Perform the plugin's task purpose.""" result = Result(result='success') cmd = render(self.cmd, **context.variables.last()) argv = shlex.split(cmd, False, False) LOGGER.debug("Running: %r" % argv) try: result['stdout'] = Plugin.run(argv) except ProcessTerminated as e: LOGGER.error("Process failed and returned %d" % e.exitCode) result = Result(result='failure') return result
def _execute_one(self, context): result = Result(result='failure') count = 0 while count < self._attempts: count += 1 LOGGER.info("%s is starting.", self._name) # emit a start event here, events MUST have correlation id start = time.time() result = object.__getattribute__(self, "_obj").execute(context) end = time.time() LOGGER.info("%s has finished with %r, in %0.9f seconds.", self._name, result['result'], (end - start)) # emit an end event here if not result and count < self._attempts: LOGGER.warning( "Task failed, will retry again. This is the %d time." % count) time.sleep(count * count) elif result: break if self._attempts > 1 and count >= self._attempts: LOGGER.error( "Task failed all retry attempts. Aborting with 'failure'.") else: if self._register is not None and context: context.variables.last()[self._register] = result return result
def execute(self, context): """Perform the plugin's task purpose.""" if context: from deployer.rendering import render msg = render(self.fail, **context.variables.last()) else: msg = self.fail LOGGER.error("| %s", msg) return Result(result='failure')
def execute(self, context): """Perform the plugin's task purpose.""" if context: msg = render(self.msg, **context.variables.last()) else: msg = self.msg for line in msg.splitlines(False): LOGGER.info("| %s", line) return Result(result='success')
def execute(self, context): """Perform the plugin's task purpose.""" with scoped_variables(context, self._scope): LOGGER.debug('Beginning stage%s' % (' (with scope)' if self._scope else '')) result = self._execute_tasks(context) LOGGER.debug('Completed stage') if result['result'] in ['skipped', 'continue']: result = Result(result='success') return result
def execute(self, context): """Perform the plugin's task purpose.""" if not context: # noqa: no-cover raise RuntimeError( "The set plug-in requires a context to function correctly") for key, value in self.variables.items(): LOGGER.debug( "Setting '%s' to '%s', in the templating environment.", key, value) context.variables.last()[key] = value return Result(result='success')
def _execute_tasks(self, context): result = Result(result='success') for node in self._tasks: for plugin in Plugin._recursive_build( node, inherited_tags=self._match_tags): result = plugin.execute(context) if not result: break if not result: break return result
def execute(self, context): """Proxy of a plug-in's `execute` method.""" result = Result(result='failed') if context and len(self._match_tags) > 0 and len(context.tags) > 0: found = False for tag in context.tags: if tag in self._match_tags: found = True if not found: LOGGER.debug( "Skipping because this item does not have a user-selected tag." ) return Result(result='skipped') if self._when is not None: expr = BooleanExpression(self._when) if not expr.evaluate(context): return Result(result='skipped') if self._with_items is not None: if context and isinstance(self._with_items, six.string_types): with_items = my_safe_eval( render(self._with_items, **context.variables.last())) else: with_items = self._with_items for item in with_items: with with_scoped_variables(context, item): result = self._execute_one(context) if not result: break else: result = self._execute_one(context) return result
def execute(self, context): """Perform the plugin's task purpose.""" result = Result(result='success') LOGGER.info("Starting pipeline execution.") start = time.time() for node in self._document: for plugin in Plugin._recursive_build(node): result = plugin.execute(context) if not result: break end = time.time() LOGGER.info("Finished pipeline execution in %0.9f seconds.", (end - start)) return result
def execute(self, context): """Perform the plugin's task purpose.""" for env in os.environ.copy(): for pattern in self.env_unset: if fnmatch.fnmatchcase(env, pattern): LOGGER.debug("Removing '%s' from system environment.", env) try: os.unsetenv(env) except AttributeError: # noqa: no-cover pass # noqa: no-cover del os.environ[env] else: LOGGER.debug( "Keeping '%s' present in the system environment.", env) for key, value in self.env_set.items(): if context: value = render(value, **context.variables.last()) LOGGER.debug("Setting '%s' to '%s', in the system environment.", key, value) os.putenv(key, value) os.environ[key] = value return Result(result='success')
def execute(self, context): """Perform the plugin's task purpose.""" result = Result(result='success') for tag in self._tags: if isinstance(self._tags, (dict, OrderedDict)): # we have a dictionary of items. LOGGER.debug("Setting environment variables for tag.") for key, value in self._tags[tag].items(): if context: value = render(value, **context.variables.last()) else: # noqa: no-cover raise RuntimeError("Context is required.") LOGGER.debug( "Setting '%s' to '%s', in the system environment.", key, value) os.putenv(key, value) os.environ[key] = value with matrix_scoped_variables(context, tag): matrix_list = [] matrix_tags = [] if context and len(context.matrix_tags) > 0: matrix_list = context.variables.last( )['matrix_list'] if 'matrix_list' in context.variables.last( ) else [] matrix_tags = context.matrix_tags if len(matrix_tags) > 0 and not all([ fnmatch.fnmatch(x[1], x[0]) for x in zip(matrix_tags, matrix_list) ]): LOGGER.debug( "Skipping because this matrix item does not have a user-selected matrix tag." ) LOGGER.debug("matrix_list=%r matrix_tags=%r", matrix_list, matrix_tags) result = Result(result='skipped') else: LOGGER.debug('Beginning matrix entry: %s', tag) result = self._execute_tasks(context) LOGGER.debug('Completed matrix entry: %s', tag) if isinstance(self._tags, (dict, OrderedDict)): # we have a dictionary of items. LOGGER.debug("Unsetting environment variables for tag.") for key, _ in self._tags[tag].items(): try: os.unsetenv(key) except AttributeError: # noqa: no-cover pass # noqa: no-cover del os.environ[key] if not result: break if result['result'] in ['skipped', 'continue']: result = Result(result='success') return result