Skip to content

Commit

Permalink
kie-issues#767: set user config for git (#4534)
Browse files Browse the repository at this point in the history
Co-authored-by: jstastny-cz <jan.stastny@ibm.com>
  • Loading branch information
jstastny-cz and jstastny-cz authored Dec 14, 2023
1 parent 59b5ddb commit 0a3679a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
26 changes: 16 additions & 10 deletions .ci/jenkins/Jenkinsfile.kie-kogito-post-release
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pipeline {
script{
sh 'printenv'
dir(docsRepo){
checkoutRepo(docsRepo, GIT_AUTHOR, getDocsRepoBranch(), GIT_AUTHOR_CREDENTIALS_ID)
checkoutRepo(docsRepo, GIT_AUTHOR, getDocsRepoBranch(), getGitAuthorCredsId())
}
}
}
Expand Down Expand Up @@ -83,6 +83,7 @@ pipeline {
dir("${docsRepo}/doc-content/kogito-docs") {
maven.mvnVersionsSet(parseVersion(getKogitoDocsVersion()))
if (githubscm.isThereAnyChanges()){
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges(commitMsg)
}
}
Expand Down Expand Up @@ -116,7 +117,7 @@ pipeline {
steps {
script {
dir("${docsRepo}/doc-content/kogito-docs") {
githubscm.pushRemoteTag('origin', "${getKogitoDocsVersion()}-kogito")
githubscm.pushRemoteTag('origin', "${getKogitoDocsVersion()}-kogito", getGitAuthorPushCredsId())
}
}
}
Expand Down Expand Up @@ -154,7 +155,7 @@ pipeline {
String prLink = commitAndCreatePR(commitMsg, PR_BRANCH, getDocsRepoBranch())
sh "git checkout ${getDocsRepoBranch()}"
mergeAndPush(prLink, getDocsRepoBranch())
githubscm.removeRemoteBranch('origin', PR_BRANCH, getGitAuthorCredsId())
githubscm.removeRemoteBranch('origin', PR_BRANCH, getGitAuthorPushCredsId())
}
}
}
Expand All @@ -170,8 +171,8 @@ pipeline {
}
}

void checkoutRepo(String repo, String GIT_AUTHOR, String branch, String GIT_AUTHOR_CREDENTIALS_ID) {
checkout(githubscm.resolveRepository(repo, GIT_AUTHOR, branch, false, GIT_AUTHOR_CREDENTIALS_ID))
void checkoutRepo(String repo, String gitAuthor, String branch, String credsId) {
checkout(githubscm.resolveRepository(repo, gitAuthor, branch, false, credsId))
// need to manually checkout branch since on a detached branch after checkout command
sh "git checkout ${branch}"
}
Expand Down Expand Up @@ -219,7 +220,11 @@ boolean isNewVersionRequired() {
}

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

String getGitAuthorPushCredsId() {
return env.GIT_AUTHOR_PUSH_CREDS_ID
}

void sendErrorNotification() {
Expand All @@ -238,14 +243,15 @@ String parseCommunityVersion(String docVersion) {

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

String commitAndCreatePR(String commitMsg, String localBranch, String targetBranch) {
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}"
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges(commitMsg)
githubscm.pushObject('origin', localBranch, getGitAuthorCredsId())
return githubscm.createPR(commitMsg, prBody, targetBranch, getGitAuthorCredsId())
githubscm.pushObject('origin', localBranch, getGitAuthorPushCredsId())
return githubscm.createPR(commitMsg, prBody, 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 @@ -37,7 +37,8 @@ void setupKogitoDocsJob() {
jobParams.env.putAll([
JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",
GIT_AUTHOR: "${GIT_AUTHOR_NAME}",
GIT_AUTHOR_CREDENTIALS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",
SSH_KOGITO_DOCS_PATH: "kogito@filemgmt-prod.jboss.org:/docs_htdocs/kogito/release",
RSYNC_KOGITO_DOCS_PATH: "kogito@filemgmt-prod-sync.jboss.org:/docs_htdocs/kogito/release",
KIE_DOCS_BRANCH: 'main-kogito',
Expand Down

0 comments on commit 0a3679a

Please sign in to comment.