forked from apache/incubator-kie-drools
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3063272
commit 684bc30
Showing
1 changed file
with
0 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1 @@ | ||
import org.jenkinsci.plugins.workflow.libs.Library | ||
@Library('jenkins-pipeline-shared-libraries')_ | ||
|
||
import org.kie.jenkins.MavenCommand | ||
|
||
previousHash = '' | ||
|
||
pipeline { | ||
agent { | ||
label 'kie-rhel8 && kie-mem16g && !built-in' | ||
} | ||
|
||
tools { | ||
maven env.BUILD_MAVEN_TOOL | ||
jdk env.BUILD_JDK_TOOL | ||
} | ||
|
||
options { | ||
timestamps() | ||
timeout(time: 180, unit: 'MINUTES') | ||
} | ||
|
||
environment { | ||
DROOLS_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") | ||
|
||
PR_BRANCH_HASH = "${util.generateHash(10)}" | ||
} | ||
|
||
stages { | ||
stage('Initialize') { | ||
steps { | ||
script { | ||
clean() | ||
|
||
if (params.DISPLAY_NAME) { | ||
currentBuild.displayName = params.DISPLAY_NAME | ||
} | ||
dir(getRepoName()) { | ||
checkoutRepo(getRepoName(), getBuildBranch()) | ||
} | ||
} | ||
} | ||
} | ||
stage('Prepare for PR') { | ||
when { | ||
expression { !isPRSourceBranch() } | ||
} | ||
steps { | ||
script { | ||
dir(getRepoName()) { | ||
githubscm.createBranch(getPRBranch()) | ||
previousHash = githubscm.getCommitHash() | ||
} | ||
} | ||
} | ||
} | ||
stage('Generate rewrite patch') { | ||
steps { | ||
script { | ||
dir(getRepoName()) { | ||
configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]) { | ||
env.BUILD_MVN_OPTS = "${env.BUILD_MVN_OPTS ?: ''} -s ${MAVEN_SETTINGS_FILE} -Dmaven.wagon.http.ssl.insecure=true -Dmaven.test.failure.ignore=true" | ||
echo "BUILD_MVN_OPTS = ${BUILD_MVN_OPTS}" | ||
|
||
sh '.ci/environments/quarkus-3/before.sh rewrite' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
stage('Push changes') { | ||
steps { | ||
script { | ||
dir(getRepoName()) { | ||
githubscm.pushObject('origin', isPRSourceBranch() ? getBuildBranch() : getPRBranch(), getGitAuthorCredsId()) | ||
} | ||
} | ||
} | ||
} | ||
stage('Create PR') { | ||
when { | ||
expression { !isPRSourceBranch() } | ||
} | ||
steps { | ||
script { | ||
dir(getRepoName()) { | ||
if (githubscm.getCommitHash() != previousHash) { | ||
def prTitle = '[Quarkus 3 migration] Updated Openrewrite patch' | ||
def prBody = "Please review and merge.\n\nGenerated by build ${BUILD_TAG}: ${BUILD_URL}." | ||
prLink = githubscm.createPR(prTitle, prBody, getBuildBranch(), getGitAuthorCredsId()) | ||
sendNotification("PR to update Quarkus 3 environment has been created.\nHere is the PR link: ${prLink}") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
unsuccessful { | ||
sendErrorNotification() | ||
} | ||
cleanup { | ||
script { | ||
clean() | ||
} | ||
} | ||
} | ||
} | ||
|
||
void clean() { | ||
sh 'rm -rf ~/.rewrite-cache/' | ||
util.cleanNode('docker') | ||
} | ||
|
||
void sendErrorNotification() { | ||
mailer.sendMarkdownTestSummaryNotification('quarkus-3', "[${getBuildBranch()}] Drools", [env.DROOLS_CI_EMAIL_TO]) | ||
} | ||
|
||
void sendNotification(String body) { | ||
emailext body: "${body}", | ||
subject: "[${getBuildBranch()}] Drools - quarkus-3", | ||
to: env.DROOLS_CI_EMAIL_TO | ||
} | ||
|
||
void checkoutRepo(String repository, String branch) { | ||
checkout(githubscm.resolveRepository(repository, getGitAuthor(), branch, false)) | ||
// need to manually checkout branch since on a detached branch after checkout command | ||
sh "git checkout ${branch}" | ||
} | ||
|
||
String getRepoName() { | ||
return env.REPO_NAME | ||
} | ||
|
||
String getGitAuthor() { | ||
// GIT_AUTHOR can be env or param | ||
return "${GIT_AUTHOR}" | ||
} | ||
|
||
String getBuildBranch() { | ||
return params.BUILD_BRANCH_NAME | ||
} | ||
|
||
boolean isPRSourceBranch() { | ||
return params.IS_PR_SOURCE_BRANCH | ||
} | ||
|
||
String getGitAuthorCredsId() { | ||
return env.AUTHOR_CREDS_ID | ||
} | ||
|
||
String getPRBranch() { | ||
return "${getBuildBranch()}-${env.PR_BRANCH_HASH}" | ||
} |