Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KOGITO-9671 CI: Remove bot account usage #1818

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
radtriste marked this conversation as resolved.
Show resolved Hide resolved
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