Skip to content

Commit

Permalink
KOGITO-9671 CI: Remove bot account usage (#1662)
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 4, 2023
1 parent 3a6158a commit 787b57a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 46 deletions.
29 changes: 12 additions & 17 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down Expand Up @@ -67,8 +67,7 @@ pipeline {
}
steps {
script {
githubscm.forkRepo(getBotAuthorCredsID())
githubscm.createBranch(getBotBranch())
githubscm.createBranch(getPRBranch())
}
}
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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))
Expand Down Expand Up @@ -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() {
Expand Down
15 changes: 5 additions & 10 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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 ?: ''
}
Expand All @@ -356,7 +351,7 @@ String getKogitoArtifactsNextVersion() {
}

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

boolean isQuayRegistry(String registry) {
Expand Down
21 changes: 8 additions & 13 deletions .ci/jenkins/Jenkinsfile.update-prod-version
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,8 +36,7 @@ pipeline {
stage('Prepare for PR') {
steps {
script {
githubscm.forkRepo(getBotAuthorCredsID())
githubscm.createBranch(getBotBranch())
githubscm.createBranch(getPRBranch())
}
}
}
Expand All @@ -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}"
}
Expand All @@ -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() {
Expand Down
6 changes: 0 additions & 6 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 787b57a

Please sign in to comment.