def slack(registry, xml_parent, data):
 def _add_xml(elem, name, value=''):
  if isinstance(value, bool):
   value = str(value).lower()
  XML.SubElement(elem, name).text = value
 logger = logging.getLogger(__name__)
 plugin_info = registry.get_plugin_info('Slack Notification Plugin')
 plugin_ver = pkg_resources.parse_version(plugin_info.get('version', '0'))
 mapping = (('team-domain', 'teamDomain', ''), ('auth-token', 'authToken', ''), ('build-server-url', 'buildServerUrl', '/'), ('room', 'room', ''))
 mapping_20 = (('notify-start', 'startNotification', False), ('notify-success', 'notifySuccess', False), ('notify-aborted', 'notifyAborted', False), ('notify-not-built', 'notifyNotBuilt', False), ('notify-unstable', 'notifyUnstable', False), ('notify-failure', 'notifyFailure', False), ('notify-back-to-normal', 'notifyBackToNormal', False), ('notify-repeated-failure', 'notifyRepeatedFailure', False), ('include-test-summary', 'includeTestSummary', False), ('commit-info-choice', 'commitInfoChoice', 'NONE'), ('include-custom-message', 'includeCustomMessage', False), ('custom-message', 'customMessage', ''))
 commit_info_choices = ['NONE', 'AUTHORS', 'AUTHORS_AND_TITLES']
 slack = XML.SubElement(xml_parent, 'jenkins.plugins.slack.SlackNotifier')
 if (plugin_ver >= pkg_resources.parse_version('2.0')):
  mapping = (mapping + mapping_20)
 if (plugin_ver < pkg_resources.parse_version('2.0')):
  for (yaml_name, _, default_value) in mapping:
   if (not data.get(yaml_name, default_value)):
    raise MissingAttributeError(yaml_name)
  for (yaml_name, _, _) in mapping_20:
   if (yaml_name in data):
    logger.warning("'%s' is invalid with plugin version < 2.0, ignored", yaml_name)
 for (yaml_name, xml_name, default_value) in mapping:
  value = data.get(yaml_name, default_value)
  if (yaml_name == 'commit-info-choice'):
   if (value not in commit_info_choices):
    raise InvalidAttributeError(yaml_name, value, commit_info_choices)
  if ((yaml_name == 'include-custom-message') and (data is False)):
   if (not data.get('custom-message', '')):
    raise MissingAttributeError('custom-message')
  _add_xml(slack, xml_name, value)

def slack ( registry , xml_parent , data ) : def _add_xml ( elem , name , value = '' ) : if isinstance ( value , bool ) : value = str ( value ) . lower ( ) XML . SubElement ( elem , name ) . text = value logger = logging . getLogger ( __name__ ) plugin_info = registry . get_plugin_info ( 'Slack Notification Plugin' ) plugin_ver = pkg_resources . parse_version ( plugin_info . get ( 'version' , '0' ) ) mapping = ( ( 'team-domain' , 'teamDomain' , '' ) , ( 'auth-token' , 'authToken' , '' ) , ( 'build-server-url' , 'buildServerUrl' , '/' ) , ( 'room' , 'room' , '' ) ) mapping_20 = ( ( 'notify-start' , 'startNotification' , False ) , ( 'notify-success' , 'notifySuccess' , False ) , ( 'notify-aborted' , 'notifyAborted' , False ) , ( 'notify-not-built' , 'notifyNotBuilt' , False ) , ( 'notify-unstable' , 'notifyUnstable' , False ) , ( 'notify-failure' , 'notifyFailure' , False ) , ( 'notify-back-to-normal' , 'notifyBackToNormal' , False ) , ( 'notify-repeated-failure' , 'notifyRepeatedFailure' , False ) , ( 'include-test-summary' , 'includeTestSummary' , False ) , ( 'commit-info-choice' , 'commitInfoChoice' , 'NONE' ) , ( 'include-custom-message' , 'includeCustomMessage' , False ) , ( 'custom-message' , 'customMessage' , '' ) ) commit_info_choices = [ 'NONE' , 'AUTHORS' , 'AUTHORS_AND_TITLES' ] slack = XML . SubElement ( xml_parent , 'jenkins.plugins.slack.SlackNotifier' ) if ( plugin_ver >= pkg_resources . parse_version ( '2.0' ) ) : mapping = ( mapping + mapping_20 ) if ( plugin_ver < pkg_resources . parse_version ( '2.0' ) ) : for ( yaml_name , _ , default_value ) in mapping : if ( not data . get ( yaml_name , default_value ) ) : raise MissingAttributeError ( yaml_name ) for ( yaml_name , _ , _ ) in mapping_20 : if ( yaml_name in data ) : logger . warning ( "'%s' is invalid with plugin version < 2.0, ignored" , yaml_name ) for ( yaml_name , xml_name , default_value ) in mapping : value = data . get ( yaml_name , default_value ) if ( yaml_name == 'commit-info-choice' ) : if ( value not in commit_info_choices ) : raise InvalidAttributeError ( yaml_name , value , commit_info_choices ) if ( ( yaml_name == 'include-custom-message' ) and ( data is False ) ) : if ( not data . get ( 'custom-message' , '' ) ) : raise MissingAttributeError ( 'custom-message' ) _add_xml ( slack , xml_name , value )
yaml: slack requires the jenkins :jenkins-wiki:slack plugin <slack+plugin> when using slack plugin version < 2 .