From bee53d4ceb4d68f76f24bec5e1cccb93ae4f9494 Mon Sep 17 00:00:00 2001 From: Tristan Radisson Date: Wed, 2 Aug 2023 16:22:49 +0200 Subject: [PATCH] KOGITO-9671 CI: Remove bot account usage (#3159) * KOGITO-9671 CI: Remove bot account usage * review comments --------- Co-authored-by: radtriste --- .ci/jenkins/Jenkinsfile.deploy | 33 +++++++------------ .ci/jenkins/Jenkinsfile.promote | 23 ++++--------- .ci/jenkins/dsl/jobs.groovy | 5 +-- .../src/test/vars/JenkinsfileDeploy.groovy | 24 ++------------ .../src/test/vars/JenkinsfilePromote.groovy | 2 +- 5 files changed, 24 insertions(+), 63 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile.deploy b/.ci/jenkins/Jenkinsfile.deploy index 5379470543f..6c772090bea 100644 --- a/.ci/jenkins/Jenkinsfile.deploy +++ b/.ci/jenkins/Jenkinsfile.deploy @@ -33,7 +33,7 @@ pipeline { // Keep here for visibility MAVEN_OPTS = '-Xms1024m -Xmx4g' - BOT_BRANCH_HASH = "${util.generateHash(10)}" + PR_BRANCH_HASH = "${util.generateHash(10)}" MAVEN_DEPLOY_LOCAL_DIR = "${WORKSPACE}/maven_deploy_dir" } @@ -82,7 +82,7 @@ pipeline { steps { script { dir(getRepoName()) { - prepareForPR() + githubscm.createBranch(getPRBranch()) } } } @@ -178,8 +178,8 @@ pipeline { post { success { script { - setDeployPropertyIfNeeded("${getRepoName()}.pr.source.uri", "https://github.com/${getBotAuthor()}/${getRepoName()}") - setDeployPropertyIfNeeded("${getRepoName()}.pr.source.ref", getBotBranch()) + setDeployPropertyIfNeeded("${getRepoName()}.pr.source.uri", "https://github.com/${getGitAuthor()}/${getRepoName()}") + setDeployPropertyIfNeeded("${getRepoName()}.pr.source.ref", getPRBranch()) setDeployPropertyIfNeeded("${getRepoName()}.pr.target.uri", "https://github.com/${getGitAuthor()}/${getRepoName()}") setDeployPropertyIfNeeded("${getRepoName()}.pr.target.ref", getBuildBranch()) } @@ -215,18 +215,13 @@ void checkoutRepo() { checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false)) } -void prepareForPR() { - githubscm.forkRepo(getBotAuthorCredsID()) - githubscm.createBranch(getBotBranch()) -} - void commitAndCreatePR() { def commitMsg = "[${getBuildBranch()}] Update version to ${getProjectVersion()}" def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it should be merged automatically." githubscm.commitChanges(commitMsg, { githubscm.findAndStageNotIgnoredFiles('pom.xml') }) - githubscm.pushObject('origin', getBotBranch(), getBotAuthorCredsID()) - deployProperties["${getRepoName()}.pr.link"] = githubscm.createPRWithLabels(commitMsg, prBody, getBuildBranch(), ['skip-ci'] as String[], getBotAuthorCredsID()) + githubscm.pushObject('origin', getPRBranch(), getGitAuthorCredsID()) + deployProperties["${getRepoName()}.pr.link"] = githubscm.createPRWithLabels(commitMsg, prBody, getBuildBranch(), ['skip-ci'] as String[], getGitAuthorCredsID()) } void sendNotification() { @@ -266,6 +261,10 @@ String getGitAuthor() { return "${GIT_AUTHOR}" } +String getGitAuthorCredsID() { + retrun env.AUTHOR_CREDS_ID +} + String getBuildBranch() { return params.BUILD_BRANCH_NAME } @@ -278,16 +277,8 @@ String getDroolsVersion() { return params.DROOLS_VERSION } -String getBotBranch() { - return "${getProjectVersion()}-${env.BOT_BRANCH_HASH}" -} - -String getBotAuthor() { - return env.GIT_AUTHOR_BOT -} - -String getBotAuthorCredsID() { - return env.BOT_CREDENTIALS_ID +String getPRBranch() { + return "${getProjectVersion()}-${env.PR_BRANCH_HASH}" } void setDeployPropertyIfNeeded(String key, def value) { diff --git a/.ci/jenkins/Jenkinsfile.promote b/.ci/jenkins/Jenkinsfile.promote index b9a197c1997..00d66bc59f0 100644 --- a/.ci/jenkins/Jenkinsfile.promote +++ b/.ci/jenkins/Jenkinsfile.promote @@ -30,7 +30,7 @@ pipeline { KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") - BOT_BRANCH_HASH = "${util.generateHash(10)}" + PR_BRANCH_HASH = "${util.generateHash(10)}" } stages { @@ -91,8 +91,9 @@ pipeline { } steps { script { - dir('bot') { - prepareForPR() + dir('pr') { + checkoutRepo() + githubscm.createBranch(getSnapshotBranch()) maven.mvnVersionsSet(getMavenCommand(), getSnapshotVersion(), true) maven.mvnSetVersionProperty(getMavenCommand(), 'version.org.kie', getDroolsSnapshotVersion()) @@ -219,10 +220,6 @@ String getGitAuthorCredsID() { return env.AUTHOR_CREDS_ID } -String getBotAuthorCredsID() { - return env.BOT_CREDENTIALS_ID -} - String getDeployPrLink() { return getDeployProperty("${getRepoName()}.pr.link") } @@ -236,7 +233,7 @@ void setPipelinePrLink(String value) { } String getSnapshotBranch() { - return "${getSnapshotVersion().toLowerCase()}-${env.BOT_BRANCH_HASH}" + return "${getSnapshotVersion().toLowerCase()}-${env.PR_BRANCH_HASH}" } ////////////////////////////////////////////////////////////////////////////// @@ -263,19 +260,13 @@ void tagLatest() { } } -void prepareForPR() { - checkoutRepo() - githubscm.forkRepo(getBotAuthorCredsID()) - githubscm.createBranch(getSnapshotBranch()) -} - void commitAndCreatePR() { def commitMsg = "[${getBuildBranch()}] Update project version to ${getSnapshotVersion()}" def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it should be merged automatically." githubscm.commitChanges(commitMsg, { githubscm.findAndStageNotIgnoredFiles('pom.xml') }) - githubscm.pushObject('origin', getSnapshotBranch(), getBotAuthorCredsID()) - setPipelinePrLink(githubscm.createPR(commitMsg, prBody, getBuildBranch(), getBotAuthorCredsID())) + githubscm.pushObject('origin', getSnapshotBranch(), getGitAuthorCredsID()) + setPipelinePrLink(githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID())) } MavenCommand getMavenCommand(String directory = '') { diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index 83d60716ce6..3cbc6cde6e1 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -181,8 +181,7 @@ void setupDeployJob(JobType jobType, String envName = '') { AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}", GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}", - GIT_AUTHOR_BOT: "${GIT_BOT_AUTHOR_NAME}", - BOT_CREDENTIALS_ID: "${GIT_BOT_AUTHOR_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}", @@ -232,8 +231,6 @@ void setupPromoteJob(JobType jobType) { AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}", GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}", - GIT_AUTHOR_BOT: "${GIT_BOT_AUTHOR_NAME}", - BOT_CREDENTIALS_ID: "${GIT_BOT_AUTHOR_CREDENTIALS_ID}", MAVEN_SETTINGS_CONFIG_FILE_ID: "${MAVEN_SETTINGS_FILE_ID}", MAVEN_DEPENDENCIES_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}", diff --git a/.ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy b/.ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy index d13a2d1a1c8..ba91278ecc7 100644 --- a/.ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy +++ b/.ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy @@ -53,32 +53,14 @@ class JenkinsfileDeploy extends JenkinsPipelineSpecification { output == 'VERSION' } - def '[Jenkinsfile.deploy] getBotBranch with version param' () { + def '[Jenkinsfile.deploy] getPRBranch with version param' () { setup: - Jenkinsfile.getBinding().setVariable('env', ['BOT_BRANCH_HASH' : 'HASH']) + Jenkinsfile.getBinding().setVariable('env', ['PR_BRANCH_HASH' : 'HASH']) Jenkinsfile.getBinding().setVariable('params', ['PROJECT_VERSION' : 'VERSION']) when: - def output = Jenkinsfile.getBotBranch() + def output = Jenkinsfile.getPRBranch() then: output == 'VERSION-HASH' } - def '[Jenkinsfile.deploy] getBotAuthor with env' () { - setup: - Jenkinsfile.getBinding().setVariable('env', ['GIT_AUTHOR_BOT' : 'AUTHOR_BOT']) - when: - def output = Jenkinsfile.getBotAuthor() - then: - output == 'AUTHOR_BOT' - } - - def '[Jenkinsfile.deploy] getBotAuthorCredsID with env' () { - setup: - Jenkinsfile.getBinding().setVariable('env', ['BOT_CREDENTIALS_ID' : 'CREDS_BOT_ID']) - when: - def output = Jenkinsfile.getBotAuthorCredsID() - then: - output == 'CREDS_BOT_ID' - } - } diff --git a/.ci/jenkins/tests/src/test/vars/JenkinsfilePromote.groovy b/.ci/jenkins/tests/src/test/vars/JenkinsfilePromote.groovy index f584aeeaf9c..6637e65c17b 100644 --- a/.ci/jenkins/tests/src/test/vars/JenkinsfilePromote.groovy +++ b/.ci/jenkins/tests/src/test/vars/JenkinsfilePromote.groovy @@ -235,7 +235,7 @@ class JenkinsfilePromote extends JenkinsPipelineSpecification { Jenkinsfile.getBinding().setVariable('params', ['PROJECT_VERSION' : '1.0.0']) explicitlyMockPipelineVariable('util') getPipelineMock('util.getNextVersion')('1.0.0', 'micro') >> { return '1.0.1-SNAPSHOT' } - Jenkinsfile.getBinding().setVariable('env', ['BOT_BRANCH_HASH' : 'anything']) + Jenkinsfile.getBinding().setVariable('env', ['PR_BRANCH_HASH' : 'anything']) when: def value = Jenkinsfile.getSnapshotBranch() then: