diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py index 4a6e61f20..9fc8afa2e 100644 --- a/jenkins_jobs/modules/project_multibranch.py +++ b/jenkins_jobs/modules/project_multibranch.py @@ -1107,6 +1107,12 @@ def build_strategies(xml_parent, data): :arg list build-strategies: Definition of build strategies. + * **all-strategies-match** (dict): All sub strategies must match for + this strategy to match. + * **strategies** (list): Sub strategies + * **any-strategies-match** (dict): Builds whenever any of the sub + strategies match. + * **strategies** (list): Sub strategies * **tags** (dict): Builds tags * **ignore-tags-newer-than** (int) The number of days since the tag was created before it is eligible for automatic building. @@ -1151,8 +1157,29 @@ def build_strategies(xml_parent, data): """ basic_build_strategies = "jenkins.branch.buildstrategies.basic" - bbs = XML.SubElement(xml_parent, "buildStrategies") - for bbs_list in data.get("build-strategies", None): + if data.get("build-strategies", None): + bbs_data = data.get("build-strategies", None) + bbs = XML.SubElement(xml_parent, "buildStrategies") + else: + bbs_data = data.get("strategies", None) + bbs = XML.SubElement(xml_parent, "strategies") + for bbs_list in bbs_data: + if "all-strategies-match" in bbs_list: + all_elem = XML.SubElement( + bbs, + "".join([basic_build_strategies, ".AllBranchBuildStrategyImpl"]), + {"plugin": "basic-branch-build-strategies"}, + ) + build_strategies(all_elem, bbs_list["all-strategies-match"]) + + if "any-strategies-match" in bbs_list: + any_elem = XML.SubElement( + bbs, + "".join([basic_build_strategies, ".AnyBranchBuildStrategyImpl"]), + {"plugin": "basic-branch-build-strategies"}, + ) + build_strategies(any_elem, bbs_list["any-strategies-match"]) + if "tags" in bbs_list: tags = bbs_list["tags"] tags_elem = XML.SubElement( diff --git a/tests/multibranch/fixtures/scm_bitbucket_full.xml b/tests/multibranch/fixtures/scm_bitbucket_full.xml index 899457676..90425c4fc 100644 --- a/tests/multibranch/fixtures/scm_bitbucket_full.xml +++ b/tests/multibranch/fixtures/scm_bitbucket_full.xml @@ -134,6 +134,23 @@ + + + + + + + + + + false + + + -1 + -1 + + + 86400000 604800000 diff --git a/tests/multibranch/fixtures/scm_bitbucket_full.yaml b/tests/multibranch/fixtures/scm_bitbucket_full.yaml index 4a7c52a47..22d0defc5 100644 --- a/tests/multibranch/fixtures/scm_bitbucket_full.yaml +++ b/tests/multibranch/fixtures/scm_bitbucket_full.yaml @@ -28,6 +28,14 @@ scm: - '+refs/heads/*:refs/remotes/@{remote}/*' - '+refs/tags/*:refs/remotes/@{remote}/*' build-strategies: + - all-strategies-match: + strategies: + - regular-branches: true + - skip-initial-build: true + - any-strategies-match: + strategies: + - change-request: {} + - tags: {} - tags: ignore-tags-newer-than: 1 ignore-tags-older-than: 7 diff --git a/tests/multibranch/fixtures/scm_gerrit_full.xml b/tests/multibranch/fixtures/scm_gerrit_full.xml index 025136735..9ccebb31b 100644 --- a/tests/multibranch/fixtures/scm_gerrit_full.xml +++ b/tests/multibranch/fixtures/scm_gerrit_full.xml @@ -64,6 +64,23 @@ + + + + + + + + + + false + + + -1 + -1 + + + 86400000 604800000 diff --git a/tests/multibranch/fixtures/scm_gerrit_full.yaml b/tests/multibranch/fixtures/scm_gerrit_full.yaml index 1f325b6d8..5d702f367 100644 --- a/tests/multibranch/fixtures/scm_gerrit_full.yaml +++ b/tests/multibranch/fixtures/scm_gerrit_full.yaml @@ -15,6 +15,14 @@ scm: query-operator: 'SCHEME' query-string: 'jenkins' build-strategies: + - all-strategies-match: + strategies: + - regular-branches: true + - skip-initial-build: true + - any-strategies-match: + strategies: + - change-request: {} + - tags: {} - tags: ignore-tags-newer-than: 1 ignore-tags-older-than: 7 diff --git a/tests/multibranch/fixtures/scm_git_full.xml b/tests/multibranch/fixtures/scm_git_full.xml index 50ecbe9ed..30aeabeb0 100644 --- a/tests/multibranch/fixtures/scm_git_full.xml +++ b/tests/multibranch/fixtures/scm_git_full.xml @@ -92,6 +92,23 @@ + + + + + + + + + + false + + + -1 + -1 + + + 86400000 604800000 diff --git a/tests/multibranch/fixtures/scm_git_full.yaml b/tests/multibranch/fixtures/scm_git_full.yaml index dc52fbcba..aaa0ce6bc 100644 --- a/tests/multibranch/fixtures/scm_git_full.yaml +++ b/tests/multibranch/fixtures/scm_git_full.yaml @@ -14,6 +14,14 @@ scm: - suppress-scm-triggering: true - pipeline-branch-durability-override: max-survivability build-strategies: + - all-strategies-match: + strategies: + - regular-branches: true + - skip-initial-build: true + - any-strategies-match: + strategies: + - change-request: {} + - tags: {} - tags: ignore-tags-newer-than: 1 ignore-tags-older-than: 7 diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml index 4272dd202..c5b883ed9 100644 --- a/tests/multibranch/fixtures/scm_github_full.xml +++ b/tests/multibranch/fixtures/scm_github_full.xml @@ -122,6 +122,23 @@ + + + + + + + + + + false + + + -1 + -1 + + + 86400000 604800000 diff --git a/tests/multibranch/fixtures/scm_github_full.yaml b/tests/multibranch/fixtures/scm_github_full.yaml index ce07fade7..92417c426 100644 --- a/tests/multibranch/fixtures/scm_github_full.yaml +++ b/tests/multibranch/fixtures/scm_github_full.yaml @@ -24,6 +24,14 @@ scm: - trigger-build-on-pr-review: true - trigger-build-on-pr-update: true build-strategies: + - all-strategies-match: + strategies: + - regular-branches: true + - skip-initial-build: true + - any-strategies-match: + strategies: + - change-request: {} + - tags: {} - tags: ignore-tags-newer-than: 1 ignore-tags-older-than: 7