Browse Source

Add cloudbees folder creation support

Add project folder module. Jenkins folder could be made with project-type: folder
This requires Cloudbees folder plugin and python-jenkins folder update
(see: https://review.openstack.org/#/c/180185/)

Change-Id: I7e1c28c26a69ae6ca736cec88fcb957a716d8fad
tags/2.0.0.0b3
Jerome Hourquebie 4 years ago
parent
commit
8bcd0d0bd2
No account linked to committer's email address

+ 7
- 0
doc/source/project_folder.rst View File

@@ -0,0 +1,7 @@
1
+.. _project_folder:
2
+
3
+Folder Project
4
+=================
5
+
6
+.. automodule:: project_folder
7
+   :members:

+ 57
- 0
jenkins_jobs/modules/project_folder.py View File

@@ -0,0 +1,57 @@
1
+# -*- coding: utf-8 -*-
2
+# Copyright (C) 2015 Cisco Systems, Inc.
3
+#
4
+# Licensed under the Apache License, Version 2.0 (the "License");
5
+# you may not use this file except in compliance with the License.
6
+# You may obtain a copy of the License at
7
+#
8
+# http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+# Unless required by applicable law or agreed to in writing, software
11
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+# License for the specific language governing permissions and limitations
14
+# under the License.
15
+
16
+
17
+"""
18
+The folder Project module handles creating Jenkins folder projects.
19
+You may specify ``folder`` in the ``project-type`` attribute of
20
+the :ref:`Job` definition.
21
+
22
+Requires the Jenkins :jenkins-wiki:`CloudBees Folder Plugin
23
+<CloudBees+Folder+Plugin>`.
24
+
25
+Job example:
26
+
27
+    .. literalinclude::
28
+      /../../tests/yamlparser/fixtures/project_folder_template001.yaml
29
+
30
+Job template example:
31
+
32
+    .. literalinclude::
33
+      /../../tests/yamlparser/fixtures/project_folder_template002.yaml
34
+
35
+"""
36
+
37
+import xml.etree.ElementTree as XML
38
+import jenkins_jobs.modules.base
39
+
40
+
41
+class Folder(jenkins_jobs.modules.base.Base):
42
+    sequence = 0
43
+
44
+    def root_xml(self, data):
45
+        xml_parent = XML.Element('com.cloudbees.hudson.plugins.folder.Folder',
46
+                                 plugin="cloudbees-folder")
47
+        XML.SubElement(xml_parent, 'actions')
48
+        attributes = {"class": "com.cloudbees.hudson.plugins.folder."
49
+                               "icons.StockFolderIcon"}
50
+        XML.SubElement(xml_parent, 'icon', attrib=attributes)
51
+        XML.SubElement(xml_parent, 'views')
52
+        attributes = {"class": "hudson.views.DefaultViewsTabBar"}
53
+        XML.SubElement(xml_parent, 'viewsTabBar', attrib=attributes)
54
+        XML.SubElement(xml_parent, 'primaryView').text = 'All'
55
+        XML.SubElement(xml_parent, 'healthMetrics')
56
+
57
+        return xml_parent

+ 1
- 0
setup.cfg View File

@@ -44,6 +44,7 @@ jjb.cli.subcommands =
44 44
 jenkins_jobs.projects =
45 45
     externaljob=jenkins_jobs.modules.project_externaljob:ExternalJob
46 46
     flow=jenkins_jobs.modules.project_flow:Flow
47
+    folder=jenkins_jobs.modules.project_folder:Folder
47 48
     freestyle=jenkins_jobs.modules.project_freestyle:Freestyle
48 49
     matrix=jenkins_jobs.modules.project_matrix:Matrix
49 50
     maven=jenkins_jobs.modules.project_maven:Maven

+ 20
- 0
tests/yamlparser/fixtures/project_folder_template001.xml View File

@@ -0,0 +1,20 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<com.cloudbees.hudson.plugins.folder.Folder plugin="cloudbees-folder">
3
+  <actions/>
4
+  <icon class="com.cloudbees.hudson.plugins.folder.icons.StockFolderIcon"/>
5
+  <views/>
6
+  <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
7
+  <primaryView>All</primaryView>
8
+  <healthMetrics/>
9
+  <actions/>
10
+  <description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
11
+  <keepDependencies>false</keepDependencies>
12
+  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
13
+  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
14
+  <concurrentBuild>false</concurrentBuild>
15
+  <canRoam>true</canRoam>
16
+  <properties/>
17
+  <scm class="hudson.scm.NullSCM"/>
18
+  <publishers/>
19
+  <buildWrappers/>
20
+</com.cloudbees.hudson.plugins.folder.Folder>

+ 3
- 0
tests/yamlparser/fixtures/project_folder_template001.yaml View File

@@ -0,0 +1,3 @@
1
+- job:
2
+    name: folder_test
3
+    project-type: folder

+ 20
- 0
tests/yamlparser/fixtures/project_folder_template002.xml View File

@@ -0,0 +1,20 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<com.cloudbees.hudson.plugins.folder.Folder plugin="cloudbees-folder">
3
+  <actions/>
4
+  <icon class="com.cloudbees.hudson.plugins.folder.icons.StockFolderIcon"/>
5
+  <views/>
6
+  <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
7
+  <primaryView>All</primaryView>
8
+  <healthMetrics/>
9
+  <actions/>
10
+  <description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
11
+  <keepDependencies>false</keepDependencies>
12
+  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
13
+  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
14
+  <concurrentBuild>false</concurrentBuild>
15
+  <canRoam>true</canRoam>
16
+  <properties/>
17
+  <scm class="hudson.scm.NullSCM"/>
18
+  <publishers/>
19
+  <buildWrappers/>
20
+</com.cloudbees.hudson.plugins.folder.Folder>

+ 8
- 0
tests/yamlparser/fixtures/project_folder_template002.yaml View File

@@ -0,0 +1,8 @@
1
+- job-template:
2
+    name: 'folder-{name}'
3
+    project-type: folder
4
+
5
+- project:
6
+    name: test
7
+    jobs:
8
+    - 'folder-{name}'

Loading…
Cancel
Save