Skip to content

Commit

Permalink
kie-issues#727: define push GH tokens for jenkins
Browse files Browse the repository at this point in the history
  • Loading branch information
jstastny-cz authored and jstastny-cz committed Dec 1, 2023
1 parent bb753e6 commit cd23128
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
12 changes: 10 additions & 2 deletions .ci/jenkins/Jenkinsfile.branch
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pipeline {
steps {
dir("${WORKSPACE}/${benchmarksRepo}") {
script {
githubscm.pushObject('origin', NEW_BRANCH)
githubscm.pushObject('origin', NEW_BRANCH, getGitAuthorPushCredsId())
}
}
}
Expand All @@ -62,6 +62,14 @@ pipeline {

void checkoutKieBenchmarksRepo() {
dir(benchmarksRepo) {
checkout(githubscm.resolveRepository(benchmarksRepo, GIT_AUTHOR, TARGET_BRANCH, false))
checkout(githubscm.resolveRepository(benchmarksRepo, GIT_AUTHOR, TARGET_BRANCH, false, getGitAuthorCredsId()))
}
}

String getGitAuthorCredsId() {
return env.GIT_AUTHOR_CREDS_ID
}

String getGitAuthorPushCredsId() {
return env.GIT_AUTHOR_PUSH_CREDS_ID
}
15 changes: 10 additions & 5 deletions .ci/jenkins/Jenkinsfile.bump-up-version
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pipeline {
String prLink = commitAndCreatePR(commitMsg, localBranch, "${getTargetBranch()}")
sh "git checkout ${getTargetBranch()}"
mergeAndPush(prLink, "${getTargetBranch()}")
githubscm.removeRemoteBranch('origin', localBranch, getGitAuthorCredsId())
githubscm.removeRemoteBranch('origin', localBranch, getGitAuthorPushCredsId())
}
}
}
Expand All @@ -73,7 +73,11 @@ String getGitAuthor() {
}

String getGitAuthorCredsId() {
return env.AUTHOR_CREDS_ID
return env.GIT_AUTHOR_CREDS_ID
}

String getGitAuthorPushCredsId() {
return env.GIT_AUTHOR_PUSH_CREDS_ID
}

String getTargetBranch() {
Expand All @@ -89,13 +93,14 @@ void checkoutRepo(String repository, String branch) {
String commitAndCreatePR(String commitMsg, String localBranch, String targetBranch) {
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}"
githubscm.commitChanges(commitMsg)
githubscm.pushObject('origin', localBranch, getGitAuthorCredsId())
githubscm.pushObject('origin', localBranch, getGitAuthorPushCredsId())
return githubscm.createPR(commitMsg, prBody, targetBranch,getGitAuthorCredsId())
}

void mergeAndPush(String prLink, String targetBranch) {
if (prLink?.trim()) {
githubscm.mergePR(prLink, getGitAuthorCredsId())
githubscm.pushObject('origin', targetBranch, getGitAuthorCredsId())
githubscm.pushObject('origin', targetBranch, getGitAuthorPushCredsId())
}
}
}

3 changes: 2 additions & 1 deletion .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void setupUpdateDependencyJob(String updateRepoName) {
UPDATE_REPO_NAME: "${updateRepoName}",

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",
AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",
])
KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
parameters {
Expand Down

0 comments on commit cd23128

Please sign in to comment.