def __environment_variables(self, secure, encrypted=False): guarded_element = PossiblyMissingElement(self.element) variable_elements = guarded_element.possibly_missing_child("environmentvariables").findall("variable") result = {} for variable_element in variable_elements: if secure == self.__is_secure(variable_element): is_encrypted = self.__is_encrypted(variable_element) value_element_name = self.__value_element_name(is_encrypted) if encrypted == is_encrypted: result[variable_element.attrib['name']] = variable_element.find(value_element_name).text return result
def parameters(self): param_elements = PossiblyMissingElement( self.element).possibly_missing_child("params").findall("param") result = {} for param_element in param_elements: result[param_element.attrib['name']] = param_element.text return result
def __sort_by_name_attribute(self, env_variables_element): environment_variable_elements = env_variables_element.findall( 'variable') PossiblyMissingElement(env_variables_element).remove_all_children( "variable") for environment_variable_element in sorted( environment_variable_elements, key=lambda e: e.attrib['name']): env_variables_element.append(environment_variable_element)
def set_git_material(self, git_material): if len(self.git_materials) > 1: raise RuntimeError( 'Cannot set git url for pipeline that already has multiple git materials. Use "ensure_material(GitMaterial(..." instead' ) PossiblyMissingElement(self.element).possibly_missing_child( 'materials').remove_all_children('git') self.__add_material(git_material) return self
def set_package_material(self, package_material): if len(self.package_materials) > 1: raise RuntimeError( 'Cannot set package ref for pipeline that already has multiple package materials. Use "ensure_material(PackageMaterial(..." instead' ) PossiblyMissingElement(self.element).possibly_missing_child( 'materials').remove_all_children('package') self.__add_material(package_material) return self
def set_has_manual_approval(self, authorize_users=None, authorize_roles=None): approval_element = Ensurance(self.element).ensure_child_with_attribute("approval", "type", "manual").element if authorize_users or authorize_roles: auth_element = Ensurance(approval_element).ensure_child('authorization').element PossiblyMissingElement(auth_element).remove_all_children() for user in (authorize_users or []): auth_element.append(ET.fromstring('<user>{}</user>'.format(user))) for role in (authorize_roles or []): auth_element.append(ET.fromstring('<role>{}</role>'.format(role))) return self
def __ensure_environment_variables(self, environment_variables, secure, encrypted): ensured_env_variables = Ensurance(self.element).ensure_child("environmentvariables") for env_variable in sorted(environment_variables.keys()): variable_element = ensured_env_variables.ensure_child_with_attribute("variable", "name", env_variable) if secure: variable_element.set("secure", "true") else: PossiblyMissingElement(variable_element.element).remove_attribute("secure") value_element = variable_element.ensure_child(self.__value_element_name(encrypted)) value_element.set_text(environment_variables[env_variable]) self.__sort_by_name_attribute(ensured_env_variables.element)
def clean_working_dir(self): return PossiblyMissingElement(self.element).has_attribute('cleanWorkingDir', "true")
def jobs(self): job_elements = PossiblyMissingElement(self.element).possibly_missing_child('jobs').findall('job') return [Job(job_element) for job_element in job_elements]
def without_any_tasks(self): PossiblyMissingElement(self.__element).possibly_missing_child("tasks").remove_all_children() return self
def templates(self): return [Pipeline(e, 'templates') for e in PossiblyMissingElement(self.__xml_root).possibly_missing_child('templates').findall('pipeline')]
def without_any_parameters(self): PossiblyMissingElement(self.element).possibly_missing_child("params").remove_all_children() return self
def fetch_materials(self, value): if value: PossiblyMissingElement(self.element).remove_attribute("fetchMaterials") else: Ensurance(self.element).set("fetchMaterials", "false")
def make_empty(self): PossiblyMissingElement(self.element).remove_all_children().remove_attribute('labeltemplate')
def _approval_authorization(self): return PossiblyMissingElement(self.element).possibly_missing_child( 'approval').possibly_missing_child('authorization')
def repositories(self): return [Repository(e) for e in PossiblyMissingElement(self.__xml_root).possibly_missing_child('repositories').findall('repository')]
def artifact_store(self): return [ ArtifactStore(e) for e in PossiblyMissingElement( self.element).findall('artifactStore') ]
def resources(self): guarded_element = PossiblyMissingElement(self.element) return set([e.text for e in guarded_element.possibly_missing_child('resources').findall('resource')])
def has_manual_approval(self): return PossiblyMissingElement(self.element).possibly_missing_child("approval").has_attribute("type", "manual")
def artifacts(self): artifact_elements = PossiblyMissingElement(self.__element).possibly_missing_child("artifacts").iterator return set([Artifact.get_artifact_for(e) for e in artifact_elements])
def fetch_materials(self): return not PossiblyMissingElement(self.element).has_attribute("fetchMaterials", "false")
def tasks(self): return [Task(e) for e in PossiblyMissingElement(self.__element).possibly_missing_child("tasks").iterator]
def materials(self): elements = PossiblyMissingElement(self.element).possibly_missing_child('materials').iterator return [Materials(element) for element in elements]
def remove_timer(self): PossiblyMissingElement(self.element).remove_all_children('timer') return self
def remove_all(self): PossiblyMissingElement(self.element).possibly_missing_child("environmentvariables").remove_all_children()
def remove_materials(self): PossiblyMissingElement(self.element).remove_all_children('materials')
def __possibly_missing_server_element(self): return PossiblyMissingElement(self.__xml_root).possibly_missing_child('server')
def tabs(self): return [Tab(e.attrib['name'], e.attrib['path']) for e in PossiblyMissingElement(self.__element).possibly_missing_child('tabs').findall('tab')]
def agents(self): return [Agent(e) for e in PossiblyMissingElement(self.__xml_root).possibly_missing_child('agents').findall('agent')]
def make_empty(self): PossiblyMissingElement(self.element).remove_all_children()
def users(self): guarded_element = PossiblyMissingElement(self.element) if guarded_element.possibly_missing_child('approval').has_attribute('type', 'manual'): return set([e.text for e in guarded_element.possibly_missing_child('approval').possibly_missing_child('authorization').findall('user')]) else: return None