Source code for pyjen.plugins.buildtriggerpublisher

"""Interface to the Jenkins 'build trigger' publishing plugin"""
from xml.etree import ElementTree
from pyjen.utils.xml_plugin import XMLPlugin


[docs]class BuildTriggerPublisher(XMLPlugin): """Interface to the Jenkins 'build trigger' publishing plugin This plugin is a default, built-in plugin which is part of the Jenkins core """
[docs] @staticmethod def get_jenkins_plugin_name(): """str: the name of the Jenkins plugin associated with this PyJen plugin This static method is used by the PyJen plugin API to associate this class with a specific Jenkins plugin, as it is encoded in the config.xml """ return "hudson.tasks.BuildTrigger"
@property def job_names(self): """list (str): names of 0 or more downstream jobs managed by this config """ children_node = self._root.find('childProjects') return [i.strip() for i in children_node.text.split(",")]
[docs] @classmethod def instantiate(cls, project_names): """Factory method for creating a new build trigger The default trigger will run when the parent job is successful Args: project_names (:class:`list` of :class:`str`): List of 1 or more names of jobs to trigger Returns: BuildTriggerPublisher: reference to the newly instantiated object """ default_xml = """ <hudson.tasks.BuildTrigger> <threshold> <name>SUCCESS</name> <ordinal>0</ordinal> <color>BLUE</color> <completeBuild>true</completeBuild> </threshold> </hudson.tasks.BuildTrigger>""" root_node = ElementTree.fromstring(default_xml) child = ElementTree.SubElement(root_node, "childProjects") child.text = ",".join(project_names) return cls(root_node)
PluginClass = BuildTriggerPublisher if __name__ == "__main__": # pragma: no cover pass