Skip to content

Commit

Permalink
KOGITO-9671 Remove bot account usage
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste committed Aug 2, 2023
1 parent 33753e1 commit 8f8f4e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
29 changes: 8 additions & 21 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -82,7 +82,7 @@ pipeline {
steps {
script {
dir(getRepoName()) {
prepareForPR()
githubscm.createBranch(getPRBranch())
}
}
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -278,16 +273,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) {
Expand Down
15 changes: 5 additions & 10 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)}"
}

stages {
Expand Down Expand Up @@ -91,7 +91,7 @@ pipeline {
}
steps {
script {
dir('bot') {
dir('pr') {
prepareForPR()

maven.mvnVersionsSet(getMavenCommand(), getSnapshotVersion(), true)
Expand Down Expand Up @@ -219,10 +219,6 @@ String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
}

String getBotAuthorCredsID() {
return env.BOT_CREDENTIALS_ID
}

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

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

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -265,7 +261,6 @@ void tagLatest() {

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

Expand All @@ -274,8 +269,8 @@ void commitAndCreatePR() {
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 = '') {
Expand Down
5 changes: 1 addition & 4 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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}",
Expand Down

0 comments on commit 8f8f4e2

Please sign in to comment.