phase1: Implement custom step ShellCommandAndSetProperty
authorChristian Marangi <ansuelsmth@gmail.com>
Wed, 13 Nov 2024 13:30:13 +0000 (14:30 +0100)
committerPetr Štetiar <ynezz@true.cz>
Mon, 18 Nov 2024 08:08:53 +0000 (08:08 +0000)
Implement custom step ShellCommandAndSetProperty, as an extension of
ShellCommand with the addition of setting a bool property that is set
True or False if the shell command succeeded or not.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
phase1/master.cfg

index f869dfc5337a30afaa0938fe3d662d6a36e2a886..82ebc90626b983a59920c538d773113e44dd2dc5 100644 (file)
@@ -17,6 +17,7 @@ from buildbot import locks
 from buildbot.data import resultspec
 from buildbot.changes.gitpoller import GitPoller
 from buildbot.config import BuilderConfig
+from buildbot.process import buildstep
 from buildbot.plugins import reporters
 from buildbot.plugins import schedulers
 from buildbot.plugins import steps
@@ -758,6 +759,37 @@ c["builders"].append(
 )
 
 
+# CUSTOM CLASS
+
+# Extension of ShellCommand and sets in property:
+# - True: the command succeded
+# - False: the command failed
+class ShellCommandAndSetProperty(buildstep.ShellMixin, buildstep.BuildStep):
+    name = "shellandsetproperty"
+    renderables = ['property']
+
+    def __init__(
+        self,
+        property=None,
+        **kwargs,
+    ):
+        kwargs = self.setupShellMixin(kwargs)
+
+        self.property = property
+
+        super().__init__(**kwargs)
+
+    @defer.inlineCallbacks
+    def run(self):
+        cmd = yield self.makeRemoteShellCommand()
+
+        yield self.runCommand(cmd)
+
+        self.setProperty(self.property, not cmd.didFail(), "ShellCommandAndSetProperty Step")
+
+        return cmd.results()
+
+
 # NB the phase1 build factory assumes workers are single-build only
 def prepareFactory(target):
     (target, subtarget) = target.split("/")