Skip to content

Commit

Permalink
KOGITO-9671 CI: Remove bot account usage (#1818)
Browse files Browse the repository at this point in the history
* KOGITO-9671 CI: Remove bot account usage

* review comments
  • Loading branch information
radtriste authored Aug 2, 2023
1 parent 24e82b2 commit 42d47be
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 43 deletions.
37 changes: 14 additions & 23 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pipeline {
MAVEN_OPTS = '-Xms1024m -Xmx4g'
NODE_OPTIONS = '--max_old_space_size=4096'

BOT_BRANCH_HASH = "${util.generateHash(10)}"
PR_BRANCH_HASH = "${util.generateHash(10)}"
MAVEN_DEPLOY_LOCAL_DIR = "${WORKSPACE}/maven_deploy_dir"
}

Expand Down Expand Up @@ -80,7 +80,9 @@ pipeline {
expression { return isRelease() || isCreatePr() }
}
steps {
prepareForPR()
dir(getRepoName()) {
githubscm.createBranch(getPRBranch())
}
}
}
stage('Update project version') {
Expand Down Expand Up @@ -161,8 +163,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())
}
Expand Down Expand Up @@ -218,13 +220,6 @@ void checkoutRepo() {
}
}

void prepareForPR() {
dir(getRepoName()) {
githubscm.forkRepo(getBotAuthorCredsID())
githubscm.createBranch(getBotBranch())
}
}

void commitAndCreatePR() {
def commitMsg = "[${getBuildBranch()}] Update version to ${getProjectVersion()}"
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}."
Expand All @@ -235,8 +230,8 @@ void commitAndCreatePR() {
}
dir(getRepoName()) {
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())
}
}

Expand Down Expand Up @@ -269,6 +264,10 @@ String getGitAuthor() {
return "${GIT_AUTHOR}"
}

String getGitAuthorCredsID() {
retrun env.AUTHOR_CREDS_ID
}

String getBuildBranch() {
return params.BUILD_BRANCH_NAME
}
Expand All @@ -277,16 +276,8 @@ String getProjectVersion() {
return params.PROJECT_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) {
Expand Down
23 changes: 7 additions & 16 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"

NODE_OPTIONS = '--max_old_space_size=4096'
}
Expand Down Expand Up @@ -83,8 +83,9 @@ pipeline {
}
steps {
script {
dir('bot') {
prepareForPR()
dir('pr') {
checkoutRepo()
githubscm.createBranch(getSnapshotBranch())

maven.mvnVersionsUpdateParentAndChildModules(getMavenCommand(), getSnapshotVersion(), true)

Expand Down Expand Up @@ -205,10 +206,6 @@ String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
}

String getBotAuthorCredsID() {
return env.BOT_CREDENTIALS_ID
}

String getDeployPrLink() {
return getDeployProperty("${getRepoName()}.pr.link")
}
Expand All @@ -222,7 +219,7 @@ void setPipelinePrLink(String value) {
}

String getSnapshotBranch() {
return "${getSnapshotVersion().toLowerCase()}-${env.BOT_BRANCH_HASH}"
return "${getSnapshotVersion().toLowerCase()}-${env.PR_BRANCH_HASH}"
}

//////////////////////////////////////////////////////////////////////////////
Expand All @@ -249,19 +246,13 @@ void tagLatest() {
}
}

void prepareForPR() {
checkoutRepo()
githubscm.forkRepo(getBotAuthorCredsID())
githubscm.createBranch(getSnapshotBranch())
}

void commitAndCreatePR() {
def commitMsg = "[${getBuildBranch()}] Update version to ${getSnapshotVersion()}"
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it should be merged automatically after testing."

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() {
Expand Down
4 changes: 0 additions & 4 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,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_DEPENDENCIES_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
MAVEN_DEPLOY_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
Expand Down Expand Up @@ -251,8 +249,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}",
Expand Down

0 comments on commit 42d47be

Please sign in to comment.