From 7814f2b120e8d6618be7176b15c49ec730240f20 Mon Sep 17 00:00:00 2001 From: Tristan Radisson Date: Wed, 2 Aug 2023 16:15:49 +0200 Subject: [PATCH] KOGITO-9671 CI: Remove bot account usage (#1662) * KOGITO-9671 CI: Remove bot account usage * review comments --- .ci/jenkins/Jenkinsfile.deploy | 29 +++++++++------------ .ci/jenkins/Jenkinsfile.promote | 15 ++++------- .ci/jenkins/Jenkinsfile.update-prod-version | 21 ++++++--------- .ci/jenkins/dsl/jobs.groovy | 6 ----- 4 files changed, 25 insertions(+), 46 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile.deploy b/.ci/jenkins/Jenkinsfile.deploy index bc10afa09..ccbccd336 100644 --- a/.ci/jenkins/Jenkinsfile.deploy +++ b/.ci/jenkins/Jenkinsfile.deploy @@ -26,7 +26,7 @@ pipeline { environment { KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") - BOT_BRANCH_HASH = "${util.generateHash(10)}" + PR_BRANCH_HASH = "${util.generateHash(10)}" OPENSHIFT_REGISTRY = credentials('OPENSHIFT_REGISTRY') } @@ -67,8 +67,7 @@ pipeline { } steps { script { - githubscm.forkRepo(getBotAuthorCredsID()) - githubscm.createBranch(getBotBranch()) + githubscm.createBranch(getPRBranch()) } } } @@ -191,15 +190,15 @@ pipeline { } prBody += '\nSee build url above for more information' } - String prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getBotAuthorCredsID()) + String prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID()) deployProperties["${getRepoName()}.pr.link"] = prLink } } post { always { 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()) } @@ -258,7 +257,7 @@ void checkoutRepo() { void commitAndPushChanges(String commitMsg) { githubscm.commitChanges(commitMsg) - githubscm.pushObject('origin', getBotBranch(), getBotAuthorCredsID()) + githubscm.pushObject('origin', getPRBranch(), getGitAuthorCredsID()) changesDone = true } @@ -272,8 +271,8 @@ void createBuildAndTestStageClosure(String image) { List buildParams = [] buildParams.add(string(name: 'DISPLAY_NAME', value: "${params.DISPLAY_NAME} - ${image}")) buildParams.add(string(name: 'BUILD_IMAGE_NAME', value: image)) - buildParams.add(string(name: 'SOURCE_AUTHOR', value: isRelease() ? getBotAuthor() : getGitAuthor())) - buildParams.add(string(name: 'SOURCE_BRANCH', value: isRelease() ? getBotBranch() : getBuildBranch())) + buildParams.add(string(name: 'SOURCE_AUTHOR', value: isRelease() ? getGitAuthor() : getGitAuthor())) + buildParams.add(string(name: 'SOURCE_BRANCH', value: isRelease() ? getPRBranch() : getBuildBranch())) buildParams.add(string(name: 'MAVEN_ARTIFACTS_REPOSITORY', value: env.MAVEN_ARTIFACT_REPOSITORY ?: (isRelease() ? env.DEFAULT_STAGING_REPOSITORY : ''))) buildParams.add(string(name: 'BUILD_KOGITO_APPS_URI', value: params.APPS_URI)) @@ -391,16 +390,12 @@ String getGitAuthor() { return "${GIT_AUTHOR}" } -String getBotBranch() { - return "${getProjectVersion() ?: getBuildBranch()}-${env.BOT_BRANCH_HASH}" +String getGitAuthorCredsID() { + retrun env.AUTHOR_CREDS_ID } -String getBotAuthor() { - return env.GIT_AUTHOR_BOT -} - -String getBotAuthorCredsID() { - return env.BOT_CREDENTIALS_ID +String getPRBranch() { + return "${getProjectVersion() ?: getBuildBranch()}-${env.PR_BRANCH_HASH}" } String getProjectVersion() { diff --git a/.ci/jenkins/Jenkinsfile.promote b/.ci/jenkins/Jenkinsfile.promote index 933d438dc..ed8078c23 100644 --- a/.ci/jenkins/Jenkinsfile.promote +++ b/.ci/jenkins/Jenkinsfile.promote @@ -28,7 +28,7 @@ pipeline { OPENSHIFT_REGISTRY = credentials('OPENSHIFT_REGISTRY') OPENSHIFT_CREDS_KEY = 'OPENSHIFT_CREDS' - BOT_BRANCH_HASH = "${util.generateHash(10)}" + PR_BRANCH_HASH = "${util.generateHash(10)}" GITHUB_REPO = "${REPO_NAME}" // for github-release cli } @@ -113,10 +113,9 @@ pipeline { script { String prLink = '' String nextVersion = getNextVersion() - dir('bot') { // Use different folder from `Update PR with released Maven artifacts` to avoid conflicts + dir('pr') { // Use different folder from `Update PR with released Maven artifacts` to avoid conflicts // Prepare PR checkoutRepo() - githubscm.forkRepo(getBotAuthorCredsID()) githubscm.createBranch(getSnapshotBranch()) // Update version to next snapshot @@ -129,8 +128,8 @@ pipeline { def commitMsg = "[${getBuildBranch()}] Update snapshot version to ${nextVersion}" def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}" githubscm.commitChanges(commitMsg) - githubscm.pushObject('origin', getSnapshotBranch(), getBotAuthorCredsID()) - prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getBotAuthorCredsID()) + githubscm.pushObject('origin', getSnapshotBranch(), getGitAuthorCredsID()) + prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID()) } dir(getRepoName()) { if (prLink) { @@ -338,10 +337,6 @@ String getGitAuthorCredsID() { return env.AUTHOR_CREDS_ID } -String getBotAuthorCredsID() { - return env.BOT_CREDENTIALS_ID -} - String getMavenArtifactRepository() { return env.MAVEN_ARTIFACT_REPOSITORY ?: '' } @@ -356,7 +351,7 @@ String getKogitoArtifactsNextVersion() { } String getSnapshotBranch() { - return "${getNextVersion()}-${env.BOT_BRANCH_HASH}" + return "${getNextVersion()}-${env.PR_BRANCH_HASH}" } boolean isQuayRegistry(String registry) { diff --git a/.ci/jenkins/Jenkinsfile.update-prod-version b/.ci/jenkins/Jenkinsfile.update-prod-version index 8715898b3..ddd12068d 100644 --- a/.ci/jenkins/Jenkinsfile.update-prod-version +++ b/.ci/jenkins/Jenkinsfile.update-prod-version @@ -16,7 +16,7 @@ pipeline { environment { // Static env is defined into ./dsl/jobs.groovy file - BOT_BRANCH_HASH = "${util.generateHash(10)}" + PR_BRANCH_HASH = "${util.generateHash(10)}" } stages { @@ -36,8 +36,7 @@ pipeline { stage('Prepare for PR') { steps { script { - githubscm.forkRepo(getBotAuthorCredsID()) - githubscm.createBranch(getBotBranch()) + githubscm.createBranch(getPRBranch()) } } } @@ -60,8 +59,8 @@ pipeline { } else { error 'No update version can be done' } - githubscm.pushObject('origin', getBotBranch(), getBotAuthorCredsID()) - String prLink = githubscm.createPR(commitMsg, 'Please review and merge', getBuildBranch(), getBotAuthorCredsID()) + githubscm.pushObject('origin', getPRBranch(), getGitAuthorCredsID()) + String prLink = githubscm.createPR(commitMsg, 'Please review and merge', getBuildBranch(), getGitAuthorCredsID()) echo "Created PR ${prLink}" } @@ -87,16 +86,12 @@ String getGitAuthor() { return "${GIT_AUTHOR}" } -String getBotBranch() { - return "${getProdProjectVersion() ?: getBuildBranch()}-${env.BOT_BRANCH_HASH}" +String getGitAuthorCredsID() { + retrun env.AUTHOR_CREDS_ID } -String getBotAuthor() { - return "${GIT_AUTHOR_BOT}" -} - -String getBotAuthorCredsID() { - return "${BOT_CREDENTIALS_ID}" +String getPRBranch() { + return "${getProdProjectVersion() ?: getBuildBranch()}-${env.PR_BRANCH_HASH}" } String getProdProjectVersion() { diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index 95a402903..590a0368d 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -127,8 +127,6 @@ 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_ARTIFACT_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}", DEFAULT_STAGING_REPOSITORY: "${MAVEN_NEXUS_STAGING_PROFILE_URL}", @@ -243,8 +241,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}", DEFAULT_STAGING_REPOSITORY: "${MAVEN_NEXUS_STAGING_PROFILE_URL}", MAVEN_ARTIFACT_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}", @@ -299,8 +295,6 @@ void setupProdUpdateVersionJob() { GIT_AUTHOR: "${GIT_AUTHOR_NAME}", 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}", ]) KogitoJobTemplate.createPipelineJob(this, jobParams)?.with { parameters {