diff --git a/.ci/jenkins/Jenkinsfile.build-and-test b/.ci/jenkins/Jenkinsfile.build-and-test index da1a49fbd..88636b9cc 100644 --- a/.ci/jenkins/Jenkinsfile.build-and-test +++ b/.ci/jenkins/Jenkinsfile.build-and-test @@ -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()) + } } } } @@ -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) @@ -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())) @@ -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 } diff --git a/.ci/jenkins/Jenkinsfile.build-image b/.ci/jenkins/Jenkinsfile.build-image index 83a3f5621..0a02478ec 100644 --- a/.ci/jenkins/Jenkinsfile.build-image +++ b/.ci/jenkins/Jenkinsfile.build-image @@ -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') @@ -361,6 +361,10 @@ String getSourceAuthor() { return params.SOURCE_AUTHOR } +String getSourceRepository() { + return params.SOURCE_REPOSITORY +} + String getSourceBranch() { return params.SOURCE_BRANCH } diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index 4997d4bed..d815d4fd6 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -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')