-
Notifications
You must be signed in to change notification settings - Fork 45
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
Showing
14 changed files
with
595 additions
and
484 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
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
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 |
---|---|---|
@@ -0,0 +1,218 @@ | ||
import org.jenkinsci.plugins.workflow.libs.Library | ||
|
||
@Library('jenkins-pipeline-shared-libraries')_ | ||
|
||
ARTIFACTS_REPOSITORIES = [ | ||
'drools' : [:], | ||
'kogito-runtimes' : [:], | ||
// 'kogito-apps' : [:], | ||
// 'kogito-examples' : [ | ||
// deploy : [ | ||
// extraParams : [ booleanParam(name: 'UPDATE_NIGHTLY_BRANCH', value: true) ] | ||
// ] | ||
// ], | ||
// 'optaplanner' : [:], | ||
// 'optaweb-vehicle-routing' : [:], | ||
// 'optaweb-employee-rostering' : [:], | ||
// 'optaplanner-quickstarts' : [ | ||
// deploy : [ | ||
// disabled : true | ||
// ] | ||
// ] | ||
] | ||
|
||
BUILD_AND_TEST_JOB_NAME_SUFFIX = 'build-and-test' | ||
DEPLOY_ARTIFACTS_JOB_NAME_SUFFIX = 'deploy-artifacts' | ||
DEPLOY_IMAGES_JOB_NAME_SUFFIX = 'deploy-images' | ||
|
||
// Map of executed jobs | ||
// See https://javadoc.jenkins.io/plugin/workflow-support/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.html | ||
// for more options on built job entity | ||
JOBS = [:] | ||
|
||
// Should be multibranch pipeline | ||
pipeline { | ||
// agent { | ||
// label 'kie-rhel7 && !master' | ||
// } | ||
agent any | ||
|
||
options { | ||
timeout(time: 1380, unit: 'MINUTES') | ||
} | ||
|
||
// parameters { | ||
// For parameters, check into ./dsl/jobs.groovy file | ||
// } | ||
|
||
environment { | ||
// Some generated env is also defined into ./dsl/jobs.groovy file | ||
|
||
KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") | ||
|
||
IMAGE_NAME_NIGHTLY_SUFFIX = 'nightly' | ||
|
||
// Use branch name in nightly tag as we may have parallel main and release branch builds | ||
NIGHTLY_TAG = """${getGitBranch()}-${sh( | ||
returnStdout: true, | ||
script: 'date -u "+%Y-%m-%d"' | ||
).trim()}""" | ||
} | ||
|
||
stages { | ||
stage('Initialize') { | ||
steps { | ||
script { | ||
echo "nightly tag is ${env.NIGHTLY_TAG}" | ||
|
||
currentBuild.displayName = env.NIGHTLY_TAG | ||
} | ||
} | ||
} | ||
|
||
// Parallel on all artifacts jobs (they should be using the build-chain) | ||
// Build and test and if ok, deploy | ||
stage('Build & Deploy artifacts') { | ||
steps { | ||
script { | ||
Map parallelJobs = [:] | ||
|
||
ARTIFACTS_REPOSITORIES.each { repo, repoConfig -> | ||
parallelJobs.put("Build & Deploy ${repo}", { | ||
boolean buildOk = true | ||
|
||
if (!repoConfig.build?.disabled) { | ||
stage("Build&Test ${repo}") { | ||
// Call build & test job | ||
def buildParams = getDefaultBuildParams() | ||
addSkipTestsParam(buildParams) | ||
addSkipIntegrationTestsParam(buildParams) | ||
if (repoConfig.build?.extraParams) { | ||
buildParams.addAll(repoConfig.deploy.extraParams) | ||
} | ||
if (isNative()) { | ||
addBooleanParam(buildParams, 'NATIVE', true) | ||
if (getNativeBuilderImage()) { | ||
addStringParam(buildParams, 'NATIVE_BUILDER_IMAGE', getNativeBuilderImage()) | ||
} | ||
} | ||
|
||
buildOk = buildJob(repo, BUILD_AND_TEST_JOB_NAME_SUFFIX, buildParams) | ||
} | ||
} | ||
|
||
if (buildOk && !repoConfig.deploy?.disabled && !isNative()) { | ||
stage("Deploy ${repo}") { | ||
// Call deploy artifacts job | ||
def buildParams = getDefaultBuildParams() | ||
if (repoConfig.deploy?.extraParams) { | ||
buildParams.addAll(repoConfig.deploy.extraParams) | ||
} | ||
|
||
buildJob(repo, DEPLOY_ARTIFACTS_JOB_NAME_SUFFIX, buildParams) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// Launch in parallel | ||
parallel parallelJobs | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
failure { | ||
mailer.sendMarkdownTestSummaryNotification("Nightly artifacts pipeline", "[${getGitBranch()}] Nightly pipeline", [env.KOGITO_CI_EMAIL_TO]) | ||
} | ||
aborted { | ||
mailer.sendMarkdownTestSummaryNotification("Nightly artifacts pipeline", "[${getGitBranch()}] Nightly pipeline", [env.KOGITO_CI_EMAIL_TO]) | ||
} | ||
} | ||
} | ||
|
||
boolean buildJob(String repo, String jobNameSuffix, List buildParams) { | ||
String jobName = constructJobName(repo, jobNameSuffix) | ||
echo "Build ${jobName} with params ${buildParams}" | ||
|
||
def job = build(job: "${jobName}", wait: true, parameters: buildParams, propagate: false) | ||
registerJob(jobName, job) | ||
|
||
// Set Unstable if job did not succeed | ||
if (!isJobSucceeded(jobName)) { | ||
unstable("Job ${jobName} finished with result ${getJobResult(jobName)}") | ||
sendJobNotification(jobName, repo) | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
String constructJobName(repo, jobNameSuffix) { | ||
return "${repo}.${jobNameSuffix}" | ||
} | ||
|
||
def registerJob(String jobName, def job) { | ||
JOBS[jobName] = job | ||
} | ||
|
||
def getJob(String jobName) { | ||
return JOBS[jobName] | ||
} | ||
|
||
String getJobUrl(String jobName) { | ||
echo "getJobUrl for ${jobName}" | ||
return getJob(jobName)?.absoluteUrl ?: '' | ||
} | ||
|
||
String getJobResult(String jobName) { | ||
echo "getJobResult for ${jobName}" | ||
return getJob(jobName)?.result ?: '' | ||
} | ||
|
||
boolean isJobSucceeded(String jobName) { | ||
return getJobResult(jobName) == 'SUCCESS' | ||
} | ||
|
||
void sendJobNotification(String jobKey, String repo) { | ||
mailer.sendMarkdownTestSummaryNotification("Nightly ${jobKey}", "[${getGitBranch()}] ${getRepoNameCamelCase(repo)}", [env.KOGITO_CI_EMAIL_TO], '', getJobUrl(jobKey)) | ||
} | ||
|
||
List getDefaultBuildParams(String key = '') { | ||
List params = [] | ||
addStringParam(params, 'DISPLAY_NAME', "${key ? "${key}-" : ''}${env.NIGHTLY_TAG}") | ||
return params | ||
} | ||
|
||
void addSkipTestsParam(buildParams) { | ||
addBooleanParam(buildParams, 'SKIP_TESTS', params.SKIP_TESTS) | ||
} | ||
|
||
void addSkipIntegrationTestsParam(buildParams) { | ||
addBooleanParam(buildParams, 'SKIP_INTEGRATION_TESTS', params.SKIP_TESTS) | ||
} | ||
|
||
void addStringParam(List params, String key, String value) { | ||
params.add(string(name: key, value: value)) | ||
} | ||
|
||
void addBooleanParam(List params, String key, boolean value) { | ||
params.add(booleanParam(name: key, value: value)) | ||
} | ||
|
||
String getGitBranch() { | ||
return env.GIT_BRANCH_NAME | ||
} | ||
|
||
boolean isNative() { | ||
return env.NATIVE ? env.NATIVE.toBoolean() : false | ||
} | ||
|
||
String getNativeBuilderImage() { | ||
return env.NATIVE_BUILDER_IMAGE | ||
} | ||
|
||
String getRepoNameCamelCase(String repoName) { | ||
List words = repoName.split('-') as List | ||
return words.collect { it.isEmpty() ? it : it.substring(0, 1).toUpperCase() + it.substring(1).toLowerCase() }.join(' ') | ||
} |
Oops, something went wrong.