blob: fd3596abe90e021c0725a008001bb4abbd8836f4 [file] [log] [blame]
import org.jenkinsci.plugins.workflow.libs.Library
@Library('jenkins-pipeline-shared-libraries')_
import org.kie.jenkins.MavenCommand
optaplannerRepo = 'optaplanner'
pipeline {
agent {
label 'kie-rhel8 && !built-in'
}
tools {
maven env.BUILD_MAVEN_TOOL
jdk env.BUILD_JDK_TOOL
}
options {
timestamps()
timeout(time: 60, unit: 'MINUTES')
}
// parameters {
// For parameters, check into ./dsl/jobs.groovy file
// }
environment {
// Static env is defined into ./dsl/jobs.groovy file
OPTAPLANNER_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}")
// Keep here for visitibility
MAVEN_OPTS = '-Xms1024m -Xmx4g'
}
stages {
stage('Initialize') {
steps {
script {
cleanWs()
if (params.DISPLAY_NAME) {
currentBuild.displayName = params.DISPLAY_NAME
}
optaplannerBranch = getBuildBranch() == 'development' ? '9.x' : getBuildBranch() == '8.x' ? 'main' : getBuildBranch()
checkoutRepo(optaplannerRepo, optaplannerBranch)
checkoutRepo(getRepoName(), getBuildBranch())
}
}
}
stage('Build OptaPlanner parents') {
steps {
script {
getMavenCommand(optaplannerRepo)
.withOptions(['-U', '-pl org.optaplanner:optaplanner-build-parent,org.optaplanner:optaplanner-bom,org.optaplanner:optaplanner-operator', '-am'])
.run('clean install')
}
}
}
stage('Update project version') {
steps {
script {
maven.mvnSetVersionProperty(getMavenCommand(getRepoName()), 'version.org.optaplanner', getOptaPlannerVersion())
maven.mvnVersionsUpdateParentAndChildModules(getMavenCommand(getRepoName()), getOptaPlannerVersion(), true)
dir(getRepoName()) {
sh "find . -name build.gradle -exec sed -i -E 's/def optaplannerVersion = \"[^\"\\s]+\"/def optaplannerVersion = \"${getOptaPlannerVersion()}\"/' {} \\;"
}
}
}
}
stage('Update branch') {
steps {
script {
dir(getRepoName()) {
if (githubscm.isThereAnyChanges()) {
def commitMsg = "Update version to ${getOptaPlannerVersion()}"
githubscm.commitChanges(commitMsg, {
githubscm.findAndStageNotIgnoredFiles('pom.xml')
githubscm.findAndStageNotIgnoredFiles('build.gradle')
})
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorCredsID())
} else {
println '[WARN] no changes to commit'
}
}
}
}
}
}
post {
unsuccessful {
sendErrorNotification()
}
cleanup {
script {
util.cleanNode('docker')
}
}
}
}
void sendErrorNotification() {
if (params.SEND_NOTIFICATION) {
String additionalInfo = "**[${getBuildBranch()}] Optaplanner Quickstarts - Setup branch**"
mailer.sendMarkdownTestSummaryNotification("CI failures", [env.OPTAPLANNER_CI_EMAIL_TO], additionalInfo)
} else {
echo 'No notification sent per configuration'
}
}
void checkoutRepo(String repository, String branch) {
dir(repository) {
deleteDir()
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
}
String getOptaPlannerVersion() {
return params.OPTAPLANNER_VERSION
}
String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
}
MavenCommand getMavenCommand(String directory) {
return new MavenCommand(this, ['-fae', '-ntp'])
.withSettingsXmlId(env.MAVEN_SETTINGS_CONFIG_FILE_ID)
.inDirectory(directory)
}