Skip to content

Commit

Permalink
kie-issues#767: set user config for git (#524)
Browse files Browse the repository at this point in the history
Co-authored-by: jstastny-cz <[email protected]>
  • Loading branch information
jstastny-cz and jstastny-cz authored Dec 14, 2023
1 parent ca638c8 commit 9833dd0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
14 changes: 9 additions & 5 deletions .ci/jenkins/Jenkinsfile.post-release
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pipeline {
script {
dir("kogito-docs-${getBuildBranch()}") {
deleteDir()
checkout(githubscm.resolveRepository('incubator-kie-kogito-docs', getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsID()))
checkout(githubscm.resolveRepository('incubator-kie-kogito-docs', getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsId()))
sh "git checkout ${getBuildBranch()}"

String antoraFile = 'serverlessworkflow/antora.yml'
Expand All @@ -70,14 +70,15 @@ pipeline {

// Add changed files, commit, open and merge PR
if (githubscm.isThereAnyChanges()) {
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges("Release Kogito ${getKogitoVersion()}")
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorCredsID())
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorPushCredsId())
} else {
echo "No changes to push."
}

// Tag repository
githubscm.tagLocalAndRemoteRepository('origin', getKogitoVersion(), getGitAuthorCredsID(), env.BUILD_TAG, true)
githubscm.tagLocalAndRemoteRepository('origin', getKogitoVersion(), getGitAuthorCredsId(), env.BUILD_TAG, true)
}
}
}
Expand Down Expand Up @@ -125,6 +126,9 @@ String getGitAuthor() {
return env.GIT_AUTHOR
}

String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
String getGitAuthorCredsId() {
return env.GIT_AUTHOR_CREDS_ID
}
String getGitAuthorPushCredsId() {
return env.GIT_AUTHOR_PUSH_CREDS_ID
}
18 changes: 12 additions & 6 deletions .ci/jenkins/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pipeline {

dir("kogito-docs-${getBuildBranch()}") {
deleteDir()
checkout(githubscm.resolveRepository('incubator-kie-kogito-docs', getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsID()))
checkout(githubscm.resolveRepository('incubator-kie-kogito-docs', getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsId()))
sh "git checkout ${getBuildBranch()}"

String[] branchSplit = getBuildBranch().split("\\.")
Expand All @@ -81,8 +81,9 @@ pipeline {

// Add changed files, commit, open and merge PR
if (githubscm.isThereAnyChanges()) {
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges("Init ${getBuildBranch()} branch")
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorCredsID())
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorPushCredsId())
} else {
echo 'No changes to push.'
}
Expand All @@ -96,7 +97,7 @@ pipeline {
script {
dir('kogito-docs') {
deleteDir()
checkout(githubscm.resolveRepository('incubator-kie-kogito-docs', getGitAuthor(), 'main', false, getGitAuthorCredsID()))
checkout(githubscm.resolveRepository('incubator-kie-kogito-docs', getGitAuthor(), 'main', false, getGitAuthorCredsId()))
sh 'git checkout main'

updateYaml('antora-playbook.yml') { antoraConfig ->
Expand All @@ -110,8 +111,9 @@ pipeline {

// Add changed files, commit, open and merge PR
if (githubscm.isThereAnyChanges()) {
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges("Add branch ${getBuildBranch()} for generation")
githubscm.pushObject('origin', 'main', getGitAuthorCredsID())
githubscm.pushObject('origin', 'main', getGitAuthorPushCredsId())
} else {
echo 'No changes to push.'
}
Expand Down Expand Up @@ -152,8 +154,12 @@ String getGitAuthor() {
return env.GIT_AUTHOR
}

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

String getGitAuthorPushCredsId() {
return env.GIT_AUTHOR_PUSH_CREDS_ID
}

void updateYaml(String filePath, Closure updateClosure) {
Expand Down
8 changes: 6 additions & 2 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ void createSetupBranchJob() {

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}",

IS_MAIN_BRANCH: "${Utils.isMainBranch(this)}"
])
Expand All @@ -80,7 +82,9 @@ void setupPostReleaseJob() {

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 9833dd0

Please sign in to comment.