Skip to content

Commit

Permalink
handle GitHub push credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
jstastny-cz committed Dec 8, 2023
1 parent 8561aa0 commit a2debcf
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions .ci/jenkins/Jenkinsfile.build-image
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pipeline {
}
options {
timeout(time: 150, unit: 'MINUTES')
skipDefaultCheckout()
}
environment {
// Linked to node label
Expand Down
19 changes: 12 additions & 7 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pipeline {

options {
timeout(time: 240, unit: 'MINUTES')
skipDefaultCheckout()
}

environment {
Expand Down Expand Up @@ -61,8 +62,8 @@ pipeline {
steps {
script {
dir(getRepoName()) {
if (githubscm.isBranchExist('origin',getPRBranch())) {
githubscm.removeRemoteBranch('origin', getPRBranch())
if (githubscm.isBranchExist('origin', getPRBranch())) {
githubscm.removeRemoteBranch('origin', getPRBranch(), getGitAuthorPushCredsId())
}
githubscm.createBranch(getPRBranch())
}
Expand Down Expand Up @@ -192,7 +193,7 @@ pipeline {
}
prBody += '\nSee build url above for more information'
}
String prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID())
String prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorPushCredsId())
deployProperties["${getRepoName()}.pr.link"] = prLink
}
}
Expand Down Expand Up @@ -255,12 +256,12 @@ String getNotificationSubject() {

void checkoutRepo() {
deleteDir()
checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false))
checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsId()))
}

void commitAndPushChanges(String commitMsg) {
githubscm.commitChanges(commitMsg)
githubscm.pushObject('origin', getPRBranch(), getGitAuthorCredsID())
githubscm.pushObject('origin', getPRBranch(), getGitAuthorPushCredsId())
changesDone = true
}

Expand Down Expand Up @@ -383,8 +384,12 @@ String getGitAuthor() {
return "${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
}

String getPRBranch() {
Expand Down
23 changes: 14 additions & 9 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pipeline {

options {
timeout(time: 120, unit: 'MINUTES')
skipDefaultCheckout()
}

environment {
Expand Down Expand Up @@ -83,8 +84,8 @@ pipeline {
// Merge PR
String prLink = getDeployProperty("${getRepoName()}.pr.link")
if (prLink) {
githubscm.mergePR(prLink, getGitAuthorCredsID())
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorCredsID())
githubscm.mergePR(prLink, getGitAuthorPushCredsId())
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorPushCredsId())
}
}
}
Expand All @@ -95,11 +96,11 @@ pipeline {
steps {
script {
dir(getRepoName()) {
if (githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsID())) {
githubscm.deleteReleaseAndTag(getGitTag(), getGitAuthorCredsID())
if (githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsId())) {
githubscm.deleteReleaseAndTag(getGitTag(), getGitAuthorPushCredsId())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTagFromVersion(getGitTag()), getGitAuthorCredsID())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsID())
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTagFromVersion(getGitTag()), getGitAuthorPushCredsId())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorPushCredsId())
}
}
}
Expand Down Expand Up @@ -135,7 +136,7 @@ String getNotificationSubject() {

void checkoutRepo() {
deleteDir()
checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false))
checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsId()))
// need to manually checkout branch since on a detached branch after checkout command
sh "git checkout ${getBuildBranch()}"
}
Expand Down Expand Up @@ -278,8 +279,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
}

boolean isQuayRegistry(String registry) {
Expand Down
12 changes: 8 additions & 4 deletions .ci/jenkins/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pipeline {
dir(getRepoName()) {
if (githubscm.isThereAnyChanges()) {
githubscm.commitChanges("[${getBuildBranch()}] Update version to ${getKogitoVersion()}")
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorCredsID())
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorPushCredsId())
} else {
println '[WARN] no changes to commit'
}
Expand Down Expand Up @@ -117,7 +117,7 @@ void sendUnsuccessfulNotification() {
void checkoutRepo(String repository, String branch) {
dir(repository) {
deleteDir()
checkout(githubscm.resolveRepository(repository, getGitAuthor(), branch, false))
checkout(githubscm.resolveRepository(repository, getGitAuthor(), branch, false, getGitAuthorCredsId()))
sh "git checkout ${branch}"
}
}
Expand All @@ -138,8 +138,12 @@ String getGitAuthor() {
return "${GIT_AUTHOR}"
}

String getGitAuthorCredsID() {
return "${AUTHOR_CREDS_ID}"
String getGitAuthorCredsId() {
return "${GIT_AUTHOR_CREDS_ID}"
}

String getGitAuthorPushCredsId() {
return "${GIT_AUTHOR_PUSH_CREDS_ID}"
}

String getKogitoVersion() {
Expand Down
11 changes: 6 additions & 5 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void createSetupBranchJob() {

JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",

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 Down Expand Up @@ -85,8 +86,8 @@ void setupDeployJob(JobType jobType) {
JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",
AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",

MAVEN_ARTIFACT_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
DEFAULT_STAGING_REPOSITORY: "${MAVEN_NEXUS_STAGING_PROFILE_URL}",
Expand Down Expand Up @@ -249,8 +250,8 @@ void setupPromoteJob(JobType jobType) {

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",

AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",

DEFAULT_STAGING_REPOSITORY: "${MAVEN_NEXUS_STAGING_PROFILE_URL}",
MAVEN_ARTIFACT_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
Expand Down

0 comments on commit a2debcf

Please sign in to comment.