Esempio n. 1
0
def reactive_choice(parser, xml_parent, data):
    """
  - reactive_choice:
      name: SNAPSHOT_NAMES
      description: "Return list of snapshot names."
      projectName: Test_Job
      referencedParameters: ENV_NAME
      script: |
        if (ENV_NAME == 'production') {
            return ['rds-backup-prod-2017-11-29',
                    'rds-backup-prod-2017-11-30']
        }
    """
    def random_with_N_digits(n):
        range_start = 10**(n - 1)
        range_end = (10**n) - 1
        return randint(range_start, range_end)

    random_num = random_with_N_digits(16)

    r_p = XML.SubElement(xml_parent, defn)
    r_p.set('plugin', '[email protected]')

    try:
        name = data['name']
    except KeyError:
        raise MissingAttributeError('name')

    try:
        script = data['script']
    except KeyError:
        raise MissingAttributeError('script')

    try:
        projectName = data['projectName']
    except KeyError:
        raise MissingAttributeError('projectName')

    choiceType = data.get('choiceType')
    if choiceType is not None and choices_type not in choices_type:
        raise MissingAttributeError('Not valid choice')

    XML.SubElement(r_p, 'name').text = name
    XML.SubElement(r_p, 'description').text = data.get('description', '')
    XML.SubElement(
        r_p, 'randomName').text = 'choice-parameter-{0}'.format(random_num)
    XML.SubElement(r_p, 'visibleItemCount').text = '1'
    XML.SubElement(r_p, 'referencedParameters').text = data.get(
        'referencedParameters', '')
    XML.SubElement(r_p, 'choiceType').text = 'PT_SINGLE_SELECT'
    XML.SubElement(r_p, 'filterable').text = 'false'
    XML.SubElement(r_p, 'filterLength').text = data.get('filterLength', '1')
    XML.SubElement(r_p, 'projectName').text = projectName

    __script = XML.SubElement(r_p, 'script')
    __script.set('class', 'org.biouno.unochoice.model.GroovyScript')
    XML.SubElement(__script, 'script').text = data.get('script', '')

    XML.SubElement(__script, 'script').text = script
    XML.SubElement(__script,
                   'fallbackScript').text = data.get('fallbackScript', '')

    __script = XML.SubElement(r_p, 'parameters')
    __script.set('class', 'linked-hash-map')
def slack(registry, xml_parent, data):
    """yaml: slack
    Requires the Jenkins :jenkins-wiki:`Slack Plugin <Slack+Plugin>`

    When using Slack Plugin version < 2.0, Slack Plugin itself requires a
    publisher aswell as properties please note that you have to add the
    publisher to your job configuration aswell. When using Slack Plugin
    version >= 2.0, you should only configure the publisher.

    :arg bool notify-start: Send notification when the job starts
        (default false)
    :arg bool notify-success: Send notification on success. (default false)
    :arg bool notify-aborted: Send notification when job is aborted. (
        default false)
    :arg bool notify-not-built: Send notification when job set to NOT_BUILT
        status. (default false)
    :arg bool notify-unstable: Send notification when job becomes unstable.
        (default false)
    :arg bool notify-failure: Send notification when job fails.
        (default false)
    :arg bool notify-back-to-normal: Send notification when job is
        succeeding again after being unstable or failed. (default false)
    :arg bool 'notify-repeated-failure': Send notification when job is
        still failing after last failure. (default false)
    :arg bool include-test-summary: Include the test summary. (default
        False)
    :arg bool include-custom-message: Include a custom message into the
        notification. (default false)
    :arg str custom-message: Custom message to be included. (default '')
    :arg str room: A comma separated list of rooms / channels to send
        the notifications to. (default '')

    Example:

    .. literalinclude::
        /../../tests/properties/fixtures/slack001.yaml
        :language: yaml
    """
    logger = logging.getLogger(__name__)

    plugin_info = registry.get_plugin_info('Slack Notification Plugin')
    plugin_ver = pkg_resources.parse_version(plugin_info.get('version', "0"))

    if plugin_ver >= pkg_resources.parse_version("2.0"):
        logger.warning(
            "properties section is not used with plugin version >= 2.0", )

    mapping = (
        ('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),
        ('include-custom-message', 'includeCustomMessage', False),
        ('custom-message', 'customMessage', ''),
        ('room', 'room', ''),
    )

    slack = XML.SubElement(
        xml_parent,
        'jenkins.plugins.slack.SlackNotifier_-SlackJobProperty',
    )

    # Ensure that custom-message is set when include-custom-message is set
    # to true.
    if data.get('include-custom-message', False):
        if not data.get('custom-message', ''):
            raise MissingAttributeError('custom-message')

    helpers.convert_mapping_to_xml(slack, data, mapping, fail_required=True)
Esempio n. 3
0
def afs_publisher(parser, xml_parent, data):
    for attr in ['site', 'source', 'target']:
        if attr not in data:
            raise MissingAttributeError(attr)