diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 59cef4fcb..f88ad2380 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -280,6 +280,47 @@ def throttle(registry, xml_parent, data): matrixopt, data, mapping, fail_required=True) +def branch_api(registry, xml_parent, data): + """yaml: branch-api + Enforces a minimum time between builds based on the desired maximum rate. + Requires the Jenkins :jenkins-wiki:`Branch API Plugin + `. + + :arg int number-of-builds: The maximum number of builds allowed within + the specified time period. (default 1) + :arg str time-period: The time period within which the maximum number + of builds will be enforced. (default 'Hour') + + :valid values: + * **Hour** + * **Day** + * **Week** + * **Month** + * **Year** + + Minimal Example: + + .. literalinclude:: + /../../tests/properties/fixtures/branch-api-minimal.yaml + :language: yaml + + Full example: + + .. literalinclude:: /../../tests/properties/fixtures/branch-api-full.yaml + :language: yaml + """ + branch = XML.SubElement(xml_parent, 'jenkins.branch.' + 'RateLimitBranchProperty_-JobPropertyImpl') + branch.set('plugin', 'branch-api') + + valid_time_periods = ['Hour', 'Day', 'Week', 'Month', 'Year'] + + mapping = [ + ('time-period', 'durationName', 'Hour', valid_time_periods), + ('number-of-builds', 'count', 1)] + helpers.convert_mapping_to_xml(branch, data, mapping, fail_required=True) + + def sidebar(registry, xml_parent, data): """yaml: sidebar Allows you to add links in the sidebar. diff --git a/tests/properties/fixtures/branch-api-full.xml b/tests/properties/fixtures/branch-api-full.xml new file mode 100644 index 000000000..e919921e5 --- /dev/null +++ b/tests/properties/fixtures/branch-api-full.xml @@ -0,0 +1,9 @@ + + + + + Day + 5 + + + diff --git a/tests/properties/fixtures/branch-api-full.yaml b/tests/properties/fixtures/branch-api-full.yaml new file mode 100644 index 000000000..fd87247bd --- /dev/null +++ b/tests/properties/fixtures/branch-api-full.yaml @@ -0,0 +1,5 @@ +properties: + - branch-api: + time-period: Day + number-of-builds: 5 + diff --git a/tests/properties/fixtures/branch-api-minimal.xml b/tests/properties/fixtures/branch-api-minimal.xml new file mode 100644 index 000000000..23e29ded4 --- /dev/null +++ b/tests/properties/fixtures/branch-api-minimal.xml @@ -0,0 +1,9 @@ + + + + + Hour + 1 + + + diff --git a/tests/properties/fixtures/branch-api-minimal.yaml b/tests/properties/fixtures/branch-api-minimal.yaml new file mode 100644 index 000000000..1cb9a8900 --- /dev/null +++ b/tests/properties/fixtures/branch-api-minimal.yaml @@ -0,0 +1,2 @@ +properties: + - branch-api