From 30855c22e8499b33729ca1c592e2a0b97a565fff Mon Sep 17 00:00:00 2001 From: Konrad Beiske Date: Mon, 9 Jul 2018 12:05:57 +0200 Subject: [PATCH] Stable identifier for branch sources in multibranch job Calculate a stable identifier based on required parameters that make up the identity of the repository so that jenkins will only require rescanning the repository if the repository was changed. Change-Id: I83da1d2478f2771e9c7808e7dbd9e6bcba5025f7 Task: 22887 Story: 2002910 --- jenkins_jobs/modules/project_multibranch.py | 11 ++++++----- tests/multibranch/fixtures/multi_scm_full.xml | 6 +++--- tests/multibranch/fixtures/multibranch_defaults.xml | 2 +- tests/multibranch/fixtures/scm_bitbucket_full.xml | 2 +- tests/multibranch/fixtures/scm_bitbucket_minimal.xml | 2 +- tests/multibranch/fixtures/scm_gerrit_full.xml | 2 +- tests/multibranch/fixtures/scm_gerrit_minimal.xml | 2 +- tests/multibranch/fixtures/scm_git_full.xml | 2 +- tests/multibranch/fixtures/scm_git_minimal.xml | 2 +- tests/multibranch/fixtures/scm_github_full.xml | 2 +- tests/multibranch/fixtures/scm_github_minimal.xml | 2 +- .../fixtures/scm_github_no_fork_pr_discovery.xml | 2 +- 12 files changed, 19 insertions(+), 18 deletions(-) diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py index eaf19d460..5e2594ff5 100644 --- a/jenkins_jobs/modules/project_multibranch.py +++ b/jenkins_jobs/modules/project_multibranch.py @@ -70,7 +70,6 @@ import logging import xml.etree.ElementTree as XML import jenkins_jobs.modules.base import jenkins_jobs.modules.helpers as helpers -import uuid import six from jenkins_jobs.errors import InvalidAttributeError @@ -328,7 +327,8 @@ def bitbucket_scm(xml_parent, data): 'plugin': 'cloudbees-bitbucket-branch-source', }) source_mapping = [ - ('', 'id', str(uuid.uuid4())), + ('', 'id', '-'.join(['bb', data.get('repo-owner', ''), + data.get('repo', '')])), ('repo-owner', 'repoOwner', None), ('repo', 'repository', None), ] @@ -414,7 +414,7 @@ def gerrit_scm(xml_parent, data): 'plugin': 'gerrit', }) source_mapping = [ - ('', 'id', str(uuid.uuid4())), + ('', 'id', '-'.join(['gr', data.get('url', '')])), ('url', 'remote', None), ('credentials-id', 'credentialsId', ''), ('includes', 'includes', '*'), @@ -485,7 +485,7 @@ def git_scm(xml_parent, data): 'plugin': 'git', }) source_mapping = [ - ('', 'id', str(uuid.uuid4())), + ('', 'id', '-'.join(['gt', data.get('url', '')])), ('url', 'remote', None), ('credentials-id', 'credentialsId', ''), ] @@ -556,7 +556,8 @@ def github_scm(xml_parent, data): 'plugin': 'github-branch-source', }) mapping = [ - ('', 'id', str(uuid.uuid4())), + ('', 'id', '-'.join(['gh', data.get('repo-owner', ''), + data.get('repo', '')])), ('repo-owner', 'repoOwner', None), ('repo', 'repository', None), ] diff --git a/tests/multibranch/fixtures/multi_scm_full.xml b/tests/multibranch/fixtures/multi_scm_full.xml index a2dfb18f2..e0af6f3c0 100644 --- a/tests/multibranch/fixtures/multi_scm_full.xml +++ b/tests/multibranch/fixtures/multi_scm_full.xml @@ -37,7 +37,7 @@ - 1-1-1-1-1 + bb-SANDBOX-test SANDBOX test secret @@ -46,7 +46,7 @@ - 1-1-1-1-1 + gt-https://example.com/jonhndoe/keep-frontend.git https://example.com/jonhndoe/keep-frontend.git secret @@ -56,7 +56,7 @@ - 1-1-1-1-1 + gh-johndoe-foo johndoe foo secret diff --git a/tests/multibranch/fixtures/multibranch_defaults.xml b/tests/multibranch/fixtures/multibranch_defaults.xml index b192ae879..061f1823d 100644 --- a/tests/multibranch/fixtures/multibranch_defaults.xml +++ b/tests/multibranch/fixtures/multibranch_defaults.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + gh-johndoe-foo johndoe foo secret diff --git a/tests/multibranch/fixtures/scm_bitbucket_full.xml b/tests/multibranch/fixtures/scm_bitbucket_full.xml index b59e64ae0..5fbcc5415 100644 --- a/tests/multibranch/fixtures/scm_bitbucket_full.xml +++ b/tests/multibranch/fixtures/scm_bitbucket_full.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + bb-SANDBOX-test SANDBOX test secret diff --git a/tests/multibranch/fixtures/scm_bitbucket_minimal.xml b/tests/multibranch/fixtures/scm_bitbucket_minimal.xml index b2a7d6b72..24ade1f42 100644 --- a/tests/multibranch/fixtures/scm_bitbucket_minimal.xml +++ b/tests/multibranch/fixtures/scm_bitbucket_minimal.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + bb-SANDBOX-test SANDBOX test diff --git a/tests/multibranch/fixtures/scm_gerrit_full.xml b/tests/multibranch/fixtures/scm_gerrit_full.xml index 92124e3fd..d7db2850b 100644 --- a/tests/multibranch/fixtures/scm_gerrit_full.xml +++ b/tests/multibranch/fixtures/scm_gerrit_full.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + gr-https://review.gerrithub.io/johndoe/foo https://review.gerrithub.io/johndoe/foo secret * diff --git a/tests/multibranch/fixtures/scm_gerrit_minimal.xml b/tests/multibranch/fixtures/scm_gerrit_minimal.xml index 03ad96cb7..609595524 100644 --- a/tests/multibranch/fixtures/scm_gerrit_minimal.xml +++ b/tests/multibranch/fixtures/scm_gerrit_minimal.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + gr-https://review.gerrithub.io/johndoe/foo https://review.gerrithub.io/johndoe/foo * diff --git a/tests/multibranch/fixtures/scm_git_full.xml b/tests/multibranch/fixtures/scm_git_full.xml index d7096791f..7f8805c04 100644 --- a/tests/multibranch/fixtures/scm_git_full.xml +++ b/tests/multibranch/fixtures/scm_git_full.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + gt-https://example.com/jonhndoe/keep-frontend.git https://example.com/jonhndoe/keep-frontend.git secret diff --git a/tests/multibranch/fixtures/scm_git_minimal.xml b/tests/multibranch/fixtures/scm_git_minimal.xml index d7a5fbaf2..0eff005b3 100644 --- a/tests/multibranch/fixtures/scm_git_minimal.xml +++ b/tests/multibranch/fixtures/scm_git_minimal.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + gt-https://example.com/jonhndoe/keep-frontend.git https://example.com/jonhndoe/keep-frontend.git diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml index 389c1b55a..7ac5359d0 100644 --- a/tests/multibranch/fixtures/scm_github_full.xml +++ b/tests/multibranch/fixtures/scm_github_full.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + gh-example-owner-example-repo example-owner example-repo http://example.org/github diff --git a/tests/multibranch/fixtures/scm_github_minimal.xml b/tests/multibranch/fixtures/scm_github_minimal.xml index 4b75b30d3..81c27b986 100644 --- a/tests/multibranch/fixtures/scm_github_minimal.xml +++ b/tests/multibranch/fixtures/scm_github_minimal.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + gh-johndoe-foo johndoe foo diff --git a/tests/multibranch/fixtures/scm_github_no_fork_pr_discovery.xml b/tests/multibranch/fixtures/scm_github_no_fork_pr_discovery.xml index a62ce9d78..e856c016b 100644 --- a/tests/multibranch/fixtures/scm_github_no_fork_pr_discovery.xml +++ b/tests/multibranch/fixtures/scm_github_no_fork_pr_discovery.xml @@ -32,7 +32,7 @@ - 1-1-1-1-1 + gh-johndoe-foo johndoe foo