Skip to content

Commit

Permalink
incubator-kie-kogito-images#1729: PR checks forks with different naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jstastny-cz committed Jun 28, 2024
1 parent 530f498 commit 3284172
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
38 changes: 27 additions & 11 deletions .ci/jenkins/Jenkinsfile.build-and-test
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ pipeline {
dir(getRepoName()) {
// TODO Test pupose
deleteDir()
githubscm.checkoutIfExists(getRepoName(), getChangeAuthor(), getChangeBranch(), 'apache', getChangeTarget(), true, credentials = [token: getGitAuthorTokenCredentialsId(), usernamePassword: getGitAuthorCredentialsId()])
if (getTargetBranch()) {
echo 'Got a target branch ... Trying to merge the source with the target'
githubscm.checkoutIfExists(getRepoName(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getTargetBranch(), true, [ token: getGitAuthorTokenCredentialsId(), usernamePassword: getGitAuthorCredentialsId() ])
githubscm.prepareCommitStatusInformationForPullRequest(getSourceRepository(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getGitAuthorCredentialsId())
} else {
echo 'No target branch ... Checking out simply'
githubscm.checkout(githubscm.resolveRepository(getSourceRepository(), getSourceAuthor(), getSourceBranch(), false, getGitAuthorCredentialsId()))
githubscm.prepareCommitStatusInformation(getSourceRepository(), getSourceAuthor(), getSourceBranch(), getGitAuthorCredentialsId())
}
}
}
}
Expand All @@ -62,7 +70,6 @@ pipeline {
steps {
script {
dir(getRepoName()) {
githubscm.prepareCommitStatusInformationForPullRequest(getRepoName(), getChangeAuthor(), getChangeBranch(), 'apache', getGitAuthorCredentialsId())
parallelStages = [:]
for(String image : getImages()){
parallelStages[image] = createBuildAndTestStageClosure(image)
Expand All @@ -88,8 +95,9 @@ Closure createBuildAndTestStageClosure(String image) {
List buildParams = []
buildParams.add(string(name: "DISPLAY_NAME", value: "PR #${getChangeId()} - ${image}: ${getChangeUrl()}"))
buildParams.add(string(name: 'BUILD_IMAGE_NAME', value: image))
buildParams.add(string(name: 'SOURCE_AUTHOR', value: getChangeAuthor()))
buildParams.add(string(name: 'SOURCE_BRANCH', value: getChangeBranch()))
buildParams.add(string(name: 'SOURCE_AUTHOR', value: getSourceAuthor()))
buildParams.add(string(name: 'SOURCE_REPOSITORY', value: getSourceRepository()))
buildParams.add(string(name: 'SOURCE_BRANCH', value: getSourceBranch()))
buildParams.add(string(name: 'TARGET_BRANCH', value: getChangeTarget()))
buildParams.add(string(name: 'BUILD_KOGITO_APPS_REF', value: getChangeTarget()))

Expand All @@ -115,30 +123,38 @@ String[] getImages() {
return sh(returnStdout: true, script: "make list | tr '\\n' ','").trim().split(',')
}

String getChangeAuthor() {
return SOURCE_AUTHOR
String getSourceAuthor() {
return params.SOURCE_AUTHOR
}

String getSourceBranch() {
return params.SOURCE_BRANCH
}

String getChangeBranch() {
return SOURCE_BRANCH
String getSourceRepository() {
return params.SOURCE_REPOSITORY
}

String getChangeTarget() {
return TARGET_BRANCH
return params.TARGET_BRANCH
}

String getChangeId() {
return CHANGE_ID
return params.CHANGE_ID
}

String getChangeUrl() {
return CHANGE_URL
return params.CHANGE_URL
}

String getRepoName() {
return env.REPO_NAME
}

String getTargetAuthor() {
return env.TARGET_AUTHOR
}

String getGitAuthorCredentialsId() {
return env.GIT_AUTHOR_CREDS_ID
}
Expand Down
10 changes: 7 additions & 3 deletions .ci/jenkins/Jenkinsfile.build-image
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ pipeline {
if (getTargetBranch()) {
echo 'Got a target branch ... Trying to merge the source with the target'
githubscm.checkoutIfExists(getRepoName(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getTargetBranch(), true, [ token: getGitAuthorTokenCredentialsId(), usernamePassword: getGitAuthorCredentialsId() ])
githubscm.prepareCommitStatusInformationForPullRequest(getRepoName(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getGitAuthorCredentialsId())
githubscm.prepareCommitStatusInformationForPullRequest(getSourceRepository(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getGitAuthorCredentialsId())
} else {
echo 'No target branch ... Checking out simply'
checkout(githubscm.resolveRepository(getRepoName(), getSourceAuthor(), getSourceBranch(), false, getGitAuthorCredentialsId()))
githubscm.prepareCommitStatusInformation(getRepoName(), getSourceAuthor(), getSourceBranch(), getGitAuthorCredentialsId())
checkout(githubscm.resolveRepository(getSourceRepository(), getSourceAuthor(), getSourceBranch(), false, getGitAuthorCredentialsId()))
githubscm.prepareCommitStatusInformation(getSourceRepository(), getSourceAuthor(), getSourceBranch(), getGitAuthorCredentialsId())
}
githubscm.setUserConfig('robot', 'kie.apache.org', true)
updateGithubCommitStatus('PENDING', 'Started')
Expand Down Expand Up @@ -361,6 +361,10 @@ String getSourceAuthor() {
return params.SOURCE_AUTHOR
}

String getSourceRepository() {
return params.SOURCE_REPOSITORY
}

String getSourceBranch() {
return params.SOURCE_BRANCH
}
Expand Down
1 change: 1 addition & 0 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ void setupBuildImageJob(JobType jobType) {
stringParam('BUILD_IMAGE_NAME', '', 'Image name to build. Mandatory parameter.')

stringParam('SOURCE_AUTHOR', Utils.getGitAuthor(this), 'Build author')
stringParam('SOURCE_REPOSITORY', Utils.getRepoName(this), 'Build repository name')
stringParam('SOURCE_BRANCH', Utils.getGitBranch(this), 'Build branch name')
stringParam('TARGET_BRANCH', '', '(Optional) In case of a PR to merge with target branch, please provide the target branch')

Expand Down

0 comments on commit 3284172

Please sign in to comment.