From 0d4d20742a70a1c8889eda90b00a543996000349 Mon Sep 17 00:00:00 2001 From: Christian Fetzer Date: Wed, 15 Jun 2016 21:19:13 +0200 Subject: [PATCH] Add support for GitLab notifier and connection property Adds a gitlab-notifier publisher that allows to set the commit status on GitLab. The GitLab connection is specified using a property. Reference: https://github.com/jenkinsci/gitlab-plugin/pull/229 Change-Id: I45b4ec2e3c5ff08922270c5c0539d4ee2086a752 --- jenkins_jobs/modules/properties.py | 22 +++++++++++++++++++ jenkins_jobs/modules/publishers.py | 15 +++++++++++++ tests/properties/fixtures/gitlab.xml | 8 +++++++ tests/properties/fixtures/gitlab.yaml | 3 +++ tests/publishers/fixtures/gitlab-notifier.xml | 6 +++++ .../publishers/fixtures/gitlab-notifier.yaml | 2 ++ 6 files changed, 56 insertions(+) create mode 100644 tests/properties/fixtures/gitlab.xml create mode 100644 tests/properties/fixtures/gitlab.yaml create mode 100644 tests/publishers/fixtures/gitlab-notifier.xml create mode 100644 tests/publishers/fixtures/gitlab-notifier.yaml diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index e9b3a1a1d..2ea842b88 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -140,6 +140,28 @@ def github(parser, xml_parent, data): raise MissingAttributeError(e) +def gitlab(parser, xml_parent, data): + """yaml: gitlab + Sets the GitLab connection for the project. Configured via Jenkins Global + Configuration. + Requires the Jenkins :jenkins-wiki:`GitLab Plugin `. + + :arg str connection: the GitLab connection name (required) + + Example: + + .. literalinclude:: /../../tests/properties/fixtures/gitlab.yaml + :language: yaml + """ + gitlab = XML.SubElement(xml_parent, + 'com.dabsquared.gitlabjenkins.connection.' + 'GitLabConnectionProperty') + try: + XML.SubElement(gitlab, 'gitLabConnection').text = data['connection'] + except KeyError as e: + raise MissingAttributeError(e) + + def least_load(parser, xml_parent, data): """yaml: least-load Enables the Least Load Plugin. diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index b29a7726d..66238b6a3 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -3969,6 +3969,21 @@ def github_notifier(parser, xml_parent, data): 'com.cloudbees.jenkins.GitHubCommitNotifier') +def gitlab_notifier(parser, xml_parent, data): + """yaml: gitlab-notifier + Set build status on GitLab commit. + Requires the Jenkins :jenkins-wiki:`GitLab Plugin `. + + Example: + + .. literalinclude:: /../../tests/publishers/fixtures/gitlab-notifier.yaml + :language: yaml + """ + XML.SubElement( + xml_parent, + 'com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher') + + def zulip(parser, xml_parent, data): """yaml: zulip Set build status on zulip. diff --git a/tests/properties/fixtures/gitlab.xml b/tests/properties/fixtures/gitlab.xml new file mode 100644 index 000000000..4ab73fef1 --- /dev/null +++ b/tests/properties/fixtures/gitlab.xml @@ -0,0 +1,8 @@ + + + + + gitlab-connection + + + diff --git a/tests/properties/fixtures/gitlab.yaml b/tests/properties/fixtures/gitlab.yaml new file mode 100644 index 000000000..fe13541c9 --- /dev/null +++ b/tests/properties/fixtures/gitlab.yaml @@ -0,0 +1,3 @@ +properties: + - gitlab: + connection: gitlab-connection diff --git a/tests/publishers/fixtures/gitlab-notifier.xml b/tests/publishers/fixtures/gitlab-notifier.xml new file mode 100644 index 000000000..9685dc9f2 --- /dev/null +++ b/tests/publishers/fixtures/gitlab-notifier.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/publishers/fixtures/gitlab-notifier.yaml b/tests/publishers/fixtures/gitlab-notifier.yaml new file mode 100644 index 000000000..5966e5ba7 --- /dev/null +++ b/tests/publishers/fixtures/gitlab-notifier.yaml @@ -0,0 +1,2 @@ +publishers: + - gitlab-notifier