Skip to content

Commit

Permalink
updated nightlies
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste committed Dec 21, 2021
1 parent 54cbbcd commit 867986b
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 484 deletions.
10 changes: 10 additions & 0 deletions .ci/jenkins/Jenkinsfile.buildchain
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pipeline {
env.BUILD_MVN_OPTS_CURRENT += isSonarCloudAnalysis() ? ' -Prun-code-coverage' : ''
env.BUILD_MVN_OPTS_CURRENT += skipTests() ? ' -DskipTests' : ''
env.BUILD_MVN_OPTS_CURRENT += skipIntegrationTests() ? ' -DskipITs' : ''
env.BUILD_MVN_OPTS_CURRENT += isNative() ? ' -Dquarkus.native.container-build=true -Dnative' : ''
env.BUILD_MVN_OPTS_CURRENT += getNativeBuilderImage() ? " -Dquarkus.native.builder-image=getNativeBuilderImage()" : ''

def buildChainActionInfo = getBuildChainActionInfo()

Expand Down Expand Up @@ -228,3 +230,11 @@ boolean skipIntegrationTests() {
boolean shouldNotify() {
return !isBranchBuildChainType()
}

boolean isNative() {
return params.NATIVE ?: (env.NATIVE ? env.NATIVE.toBoolean() : false)
}

String getNativeBuilderImage() {
return params.NATIVE_BUILDER_IMAGE ?: (env.NATIVE_BUILDER_IMAGE ? env.NATIVE_BUILDER_IMAGE.toBoolean() : false)
}
4 changes: 0 additions & 4 deletions .ci/jenkins/Jenkinsfile.ecosystem.update-version
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,6 @@ boolean isOperatorDeploy() {
return !params.SKIP_OPERATOR
}

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(' ')
Expand Down
218 changes: 218 additions & 0 deletions .ci/jenkins/Jenkinsfile.nightly.artifacts
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(' ')
}
Loading

0 comments on commit 867986b

Please sign in to comment.