From e176629af2799348c4085dd29088376a4376fd62 Mon Sep 17 00:00:00 2001 From: jstastny-cz Date: Tue, 28 Nov 2023 13:36:54 +0100 Subject: [PATCH] kie-issues#727: define push GH tokens for jenkins --- .ci/jenkins/Jenkinsfile.branch | 12 ++++++++++-- .ci/jenkins/Jenkinsfile.bump-up-version | 15 ++++++++++----- .ci/jenkins/dsl/jobs.groovy | 3 ++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile.branch b/.ci/jenkins/Jenkinsfile.branch index 8d3c792e..867711bc 100644 --- a/.ci/jenkins/Jenkinsfile.branch +++ b/.ci/jenkins/Jenkinsfile.branch @@ -47,7 +47,7 @@ pipeline { steps { dir("${WORKSPACE}/${benchmarksRepo}") { script { - githubscm.pushObject('origin', NEW_BRANCH) + githubscm.pushObject('origin', NEW_BRANCH, getGitAuthorPushCredsId()) } } } @@ -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 +} diff --git a/.ci/jenkins/Jenkinsfile.bump-up-version b/.ci/jenkins/Jenkinsfile.bump-up-version index 471254f7..52ce6925 100644 --- a/.ci/jenkins/Jenkinsfile.bump-up-version +++ b/.ci/jenkins/Jenkinsfile.bump-up-version @@ -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()) } } } @@ -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() { @@ -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()) } -} \ No newline at end of file +} + diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index 95897990..53e753ee 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -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 {