From 95f6461feb5d19e6ba0155f7c05ea6ec25f286cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Biarn=C3=A9s=20Kiefer?= Date: Tue, 8 Aug 2023 15:13:42 +0200 Subject: [PATCH] KOGITO-5386: added a new parameter for unique branch name (#3161) --- .ci/jenkins/Jenkinsfile.deploy | 5 ++++- .ci/jenkins/dsl/jobs.groovy | 3 ++- .ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy | 9 ++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile.deploy b/.ci/jenkins/Jenkinsfile.deploy index 9f37db7351d..c5af11b66ad 100644 --- a/.ci/jenkins/Jenkinsfile.deploy +++ b/.ci/jenkins/Jenkinsfile.deploy @@ -82,6 +82,9 @@ pipeline { steps { script { dir(getRepoName()) { + if (githubscm.isBranchExist('origin',getPRBranch())) { + githubscm.removeRemoteBranch('origin', getPRBranch()) + } githubscm.createBranch(getPRBranch()) } } @@ -274,7 +277,7 @@ String getDroolsVersion() { } String getPRBranch() { - return "${getProjectVersion()}-${env.PR_BRANCH_HASH}" + return params.KOGITO_PR_BRANCH } void setDeployPropertyIfNeeded(String key, def value) { diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index 3cbc6cde6e1..eb83fd3adca 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -181,7 +181,7 @@ void setupDeployJob(JobType jobType, String envName = '') { AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}", GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}", - + MAVEN_DEPENDENCIES_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}", MAVEN_DEPLOY_REPOSITORY: "${MAVEN_ARTIFACTS_UPLOAD_REPOSITORY_URL}", MAVEN_REPO_CREDS_ID: "${MAVEN_ARTIFACTS_UPLOAD_REPOSITORY_CREDS_ID}", @@ -212,6 +212,7 @@ void setupDeployJob(JobType jobType, String envName = '') { booleanParam('CREATE_PR', false, 'Should we create a PR with the changes ?') stringParam('PROJECT_VERSION', '', 'Set the project version') stringParam('DROOLS_VERSION', '', 'Drools version to set') + stringParam('KOGITO_PR_BRANCH', '', 'PR branch name') booleanParam('SEND_NOTIFICATION', false, 'In case you want the pipeline to send a notification on CI channel for this run.') } diff --git a/.ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy b/.ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy index ba91278ecc7..aa9788b88a1 100644 --- a/.ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy +++ b/.ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy @@ -35,7 +35,7 @@ class JenkinsfileDeploy extends JenkinsPipelineSpecification { output == 'AUTHOR' } - def '[Jenkinsfile.deploy] getBuildBranch()' () { + def '[Jenkinsfile.deploy] getBuildBranch' () { setup: Jenkinsfile.getBinding().setVariable('params', ['BUILD_BRANCH_NAME' : 'BRANCH']) when: @@ -53,14 +53,13 @@ class JenkinsfileDeploy extends JenkinsPipelineSpecification { output == 'VERSION' } - def '[Jenkinsfile.deploy] getPRBranch with version param' () { + def '[Jenkinsfile.deploy] getPRBranch with pr branch param' () { setup: - Jenkinsfile.getBinding().setVariable('env', ['PR_BRANCH_HASH' : 'HASH']) - Jenkinsfile.getBinding().setVariable('params', ['PROJECT_VERSION' : 'VERSION']) + Jenkinsfile.getBinding().setVariable('params', ['KOGITO_PR_BRANCH' : 'PR_BRANCH']) when: def output = Jenkinsfile.getPRBranch() then: - output == 'VERSION-HASH' + output == 'PR_BRANCH' } }