def write_job_shell(self, name, text, num = 0): ''' name: Job name, 'str' num: post steps num, 'int' text: Execute Shell Script, 'str' ''' xml = self.get_job_config(name) self.tree = XMLlib.read_xml_string(xml) #create add insert hudson node get_postbuilder = XMLlib.find_nodes(self.tree, "postbuilders") if XMLlib.find_nodes(self.tree, "postbuilders/hudson.tasks.Shell") == []: hudson_node = XMLlib.create_node("hudson.tasks.Shell", {}, "") XMLlib.add_child_node(get_postbuilder, hudson_node) #create add insert command node get_hudson = XMLlib.find_nodes(self.tree, "postbuilders/hudson.tasks.Shell") if XMLlib.find_nodes(self.tree, "postbuilders/hudson.tasks.Shell/command") == []: command_node = XMLlib.create_node("command", {}, text) XMLlib.add_child_node(get_hudson, command_node) else: command_node = XMLlib.find_nodes(self.tree, "postbuilders/hudson.tasks.Shell/command") XMLlib.change_node_text(command_node, text) self.__post_steps(num) reconf = XMLlib.print_xml(self.tree) self.reconfig_job(name, reconf.encode("utf-8"))
def __post_steps(self, num): select = { 0: ["SUCCESS", "0", "BLUE"], 1: ["test1", "1", "YELLOW"], 2: ["test2", "2", "RED"] } name = XMLlib.find_nodes(self.tree, "runPostStepsIfResult/name") XMLlib.change_node_text(name, select[num][0]) ordinal = XMLlib.find_nodes(self.tree, "runPostStepsIfResult/ordinal") XMLlib.change_node_text(ordinal, select[num][1]) color = XMLlib.find_nodes(self.tree, "runPostStepsIfResult/color") XMLlib.change_node_text(color, select[num][2])