Skip to content

Commit

Permalink
Split nightly job
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste committed Mar 16, 2022
1 parent f671ae3 commit 9b8686b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 123 deletions.
123 changes: 19 additions & 104 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import org.kie.jenkins.jobdsl.model.Folder
import org.kie.jenkins.jobdsl.templates.KogitoJobTemplate
import org.kie.jenkins.jobdsl.FolderUtils
import org.kie.jenkins.jobdsl.KogitoJobType
import org.kie.jenkins.jobdsl.KogitoJobUtils
import org.kie.jenkins.jobdsl.Utils

JENKINSFILE_PATH = '.ci/jenkins'

def getDefaultJobParams() {
def jobParams = KogitoJobTemplate.getDefaultJobParams(this, 'kogito-runtimes')
def jobParams = KogitoJobUtils.getDefaultJobParams(this, 'kogito-runtimes')
jobParams.pr.excluded_regions.add('docsimg/.*')
return jobParams
}

def getJobParams(String jobName, String jobFolder, String jenkinsfileName, String jobDescription = '') {
def jobParams = getDefaultJobParams()
jobParams.job.name = jobName
jobParams.job.folder = jobFolder
jobParams.jenkinsfile = jenkinsfileName
if (jobDescription) {
jobParams.job.description = jobDescription
}
return jobParams
def getJobParams(String jobName, Folder jobFolder, String jenkinsfileName, String jobDescription = '') {
return KogitoJobUtils.getBasicJobParams(this, { return getDefaultJobParams() }, jobName, jobFolder, jenkinsfileName, jobDescription)
}

Map getMultijobPRConfig(boolean isNative = false) {
Map getMultijobPRConfig(Folder jobFolder) {
return [
parallel: true,
buildchain: true,
Expand All @@ -41,7 +33,7 @@ Map getMultijobPRConfig(boolean isNative = false) {
dependsOn: 'kogito-runtimes',
repository: 'kogito-apps',
env : [
ADDITIONAL_TIMEOUT: isNative ? '360' : '210',
ADDITIONAL_TIMEOUT: jobFolder.isNativeEnvironment() ? '360' : '210',
]
], [
id: 'kogito-examples',
Expand All @@ -53,81 +45,38 @@ Map getMultijobPRConfig(boolean isNative = false) {
}

if (Utils.isMainBranch(this)) {
setupDeployJob(FolderUtils.getPullRequestRuntimesBDDFolder(this), KogitoJobType.PR)
setupDeployJob(Folder.PULLREQUEST_RUNTIMES_BD)

// Sonarcloud analysis only on main branch
// As we have only Community edition
setupSonarCloudJob()
}

// PR checks
setupMultijobPrDefaultChecks()
setupMultijobPrNativeChecks()
setupMultijobPrLTSChecks()
KogitoJobUtils.createAllEnvsPerRepoPRJobs(this, { jobFolder -> getMultijobPRConfig(jobFolder) }, { return getDefaultJobParams() })

// Nightly jobs
if (Utils.isMainBranch(this)) {
setupQuarkusJob('main')
}
setupNativeJob()
setupDeployJob(FolderUtils.getNightlyFolder(this), KogitoJobType.NIGHTLY)
setupPromoteJob(FolderUtils.getNightlyFolder(this), KogitoJobType.NIGHTLY)
KogitoJobUtils.createAllJobsForArtifactsRepository(this, 'kogito-runtimes', ['drools', 'kogito'])

// No release directly on main branch
if (!Utils.isMainBranch(this)) {
setupDeployJob(FolderUtils.getReleaseFolder(this), KogitoJobType.RELEASE)
setupPromoteJob(FolderUtils.getReleaseFolder(this), KogitoJobType.RELEASE)
}

if (Utils.isLTSBranch(this)) {
setupQuarkusJob(Utils.getQuarkusLTSVersion(this))
setupNativeLTSJob()
setupDeployJob(Folder.RELEASE)
setupPromoteJob(Folder.RELEASE)
}

// Tools job
KogitoJobUtils.createQuarkusUpdateToolsJob(this, 'kogito-runtimes', 'Kogito Runtimes', [
KogitoJobUtils.createQuarkusUpdateToolsJob(this, 'kogito-runtimes', [
modules: [ 'kogito-dependencies-bom', 'kogito-build-parent', 'kogito-quarkus-bom', 'kogito-build-no-bom-parent' ],
compare_deps_remote_poms: [ 'io.quarkus:quarkus-bom' ],
properties: [ 'version.io.quarkus', 'version.io.quarkus.quarkus-test-maven' ],
])
KogitoJobUtils.createKie7UpdateToolsJob(this, 'kogito-runtimes', 'Kogito Runtimes', [
modules: [ 'kogito-kie-bom' ],
properties: [ 'version.org.kie' ],
])

/////////////////////////////////////////////////////////////////
// Methods
/////////////////////////////////////////////////////////////////

void setupMultijobPrDefaultChecks() {
KogitoJobTemplate.createMultijobPRJobs(this, getMultijobPRConfig()) { return getDefaultJobParams() }
}

void setupMultijobPrNativeChecks() {
KogitoJobTemplate.createMultijobNativePRJobs(this, getMultijobPRConfig(true)) { return getDefaultJobParams() }
}

void setupMultijobPrLTSChecks() {
KogitoJobTemplate.createMultijobLTSPRJobs(this, getMultijobPRConfig()) { return getDefaultJobParams() }
}

void setupQuarkusJob(String quarkusBranch) {
def jobParams = getJobParams("kogito-quarkus-${quarkusBranch}", FolderUtils.getNightlyFolder(this), "${JENKINSFILE_PATH}/Jenkinsfile.quarkus", 'Kogito Runtimes Quarkus Snapshot')
jobParams.triggers = [ cron : 'H 4 * * *' ]
KogitoJobTemplate.createPipelineJob(this, jobParams).with {
parameters {
stringParam('BUILD_BRANCH_NAME', "${GIT_BRANCH}", 'Set the Git branch to checkout')
stringParam('GIT_AUTHOR', "${GIT_AUTHOR_NAME}", 'Set the Git author to checkout')
}
environmentVariables {
env('JENKINS_EMAIL_CREDS_ID', "${JENKINS_EMAIL_CREDS_ID}")
env('QUARKUS_BRANCH', quarkusBranch)
}
}
}

void setupSonarCloudJob() {
def jobParams = getJobParams('kogito-runtimes-sonarcloud', FolderUtils.getNightlyFolder(this), "${JENKINSFILE_PATH}/Jenkinsfile.sonarcloud", 'Kogito Runtimes Daily Sonar')
def jobParams = getJobParams('kogito-runtimes-sonarcloud', Folder.NIGHTLY, "${JENKINSFILE_PATH}/Jenkinsfile.sonarcloud", 'Kogito Runtimes Daily Sonar')
jobParams.triggers = [ cron : 'H 20 * * 1-5' ]
KogitoJobTemplate.createPipelineJob(this, jobParams).with {
parameters {
Expand All @@ -140,41 +89,9 @@ void setupSonarCloudJob() {
}
}

void setupNativeJob() {
def jobParams = getJobParams('kogito-runtimes-native', FolderUtils.getNightlyFolder(this), "${JENKINSFILE_PATH}/Jenkinsfile.native", 'Kogito Runtimes Native Testing')
jobParams.triggers = [ cron : 'H 6 * * *' ]
KogitoJobTemplate.createPipelineJob(this, jobParams).with {
parameters {
stringParam('BUILD_BRANCH_NAME', "${GIT_BRANCH}", 'Set the Git branch to checkout')
stringParam('GIT_AUTHOR', "${GIT_AUTHOR_NAME}", 'Set the Git author to checkout')
}
environmentVariables {
env('JENKINS_EMAIL_CREDS_ID', "${JENKINS_EMAIL_CREDS_ID}")
env('NOTIFICATION_JOB_NAME', 'Native check')
}
}
}

void setupNativeLTSJob() {
def jobParams = getJobParams('kogito-runtimes-native-lts', FolderUtils.getNightlyFolder(this), "${JENKINSFILE_PATH}/Jenkinsfile.native", 'Kogito Runtimes Native LTS Testing')
jobParams.triggers = [ cron : 'H 8 * * *' ]
KogitoJobTemplate.createPipelineJob(this, jobParams).with {
parameters {
stringParam('BUILD_BRANCH_NAME', "${GIT_BRANCH}", 'Set the Git branch to checkout')
stringParam('GIT_AUTHOR', "${GIT_AUTHOR_NAME}", 'Set the Git author to checkout')

stringParam('NATIVE_BUILDER_IMAGE', Utils.getLTSNativeBuilderImage(this), 'Which native builder image to use ?')
}
environmentVariables {
env('JENKINS_EMAIL_CREDS_ID', "${JENKINS_EMAIL_CREDS_ID}")
env('NOTIFICATION_JOB_NAME', 'Native LTS check')
}
}
}

void setupDeployJob(String jobFolder, KogitoJobType jobType) {
void setupDeployJob(Folder jobFolder) {
def jobParams = getJobParams('kogito-runtimes-deploy', jobFolder, "${JENKINSFILE_PATH}/Jenkinsfile.deploy", 'Kogito Runtimes Deploy')
if (jobType == KogitoJobType.PR) {
if (jobFolder.isPullRequestFolder()) {
jobParams.git.branch = '${BUILD_BRANCH_NAME}'
jobParams.git.author = '${GIT_AUTHOR}'
jobParams.git.project_url = Utils.createProjectUrl("${GIT_AUTHOR_NAME}", jobParams.git.repository)
Expand All @@ -184,7 +101,7 @@ void setupDeployJob(String jobFolder, KogitoJobType jobType) {
stringParam('DISPLAY_NAME', '', 'Setup a specific build display name')

stringParam('BUILD_BRANCH_NAME', "${GIT_BRANCH}", 'Set the Git branch to checkout')
if (jobType == KogitoJobType.PR) {
if (jobFolder.isPullRequestFolder()) {
// author can be changed as param only for PR behavior, due to source branch/target, else it is considered as an env
stringParam('GIT_AUTHOR', "${GIT_AUTHOR_NAME}", 'Set the Git author to checkout')
}
Expand All @@ -203,11 +120,10 @@ void setupDeployJob(String jobFolder, KogitoJobType jobType) {
environmentVariables {
env('REPO_NAME', 'kogito-runtimes')

env('RELEASE', jobType == KogitoJobType.RELEASE)
env('JENKINS_EMAIL_CREDS_ID', "${JENKINS_EMAIL_CREDS_ID}")
env('MAVEN_SETTINGS_CONFIG_FILE_ID', "${MAVEN_SETTINGS_FILE_ID}")

if (jobType == KogitoJobType.PR) {
if (jobFolder.isPullRequestFolder()) {
env('MAVEN_DEPENDENCIES_REPOSITORY', "${MAVEN_PR_CHECKS_REPOSITORY_URL}")
env('MAVEN_DEPLOY_REPOSITORY', "${MAVEN_PR_CHECKS_REPOSITORY_URL}")
env('MAVEN_REPO_CREDS_ID', "${MAVEN_PR_CHECKS_REPOSITORY_CREDS_ID}")
Expand All @@ -221,7 +137,7 @@ void setupDeployJob(String jobFolder, KogitoJobType jobType) {

env('MAVEN_DEPENDENCIES_REPOSITORY', "${MAVEN_ARTIFACTS_REPOSITORY}")
env('MAVEN_DEPLOY_REPOSITORY', "${MAVEN_ARTIFACTS_REPOSITORY}")
if (jobType == KogitoJobType.RELEASE) {
if (jobFolder.isReleaseFolder()) {
env('NEXUS_RELEASE_URL', "${MAVEN_NEXUS_RELEASE_URL}")
env('NEXUS_RELEASE_REPOSITORY_ID', "${MAVEN_NEXUS_RELEASE_REPOSITORY}")
env('NEXUS_STAGING_PROFILE_ID', "${MAVEN_NEXUS_STAGING_PROFILE_ID}")
Expand All @@ -232,7 +148,7 @@ void setupDeployJob(String jobFolder, KogitoJobType jobType) {
}
}

void setupPromoteJob(String jobFolder, KogitoJobType jobType) {
void setupPromoteJob(Folder jobFolder) {
KogitoJobTemplate.createPipelineJob(this, getJobParams('kogito-runtimes-promote', jobFolder, "${JENKINSFILE_PATH}/Jenkinsfile.promote", 'Kogito Runtimes Promote')).with {
parameters {
stringParam('DISPLAY_NAME', '', 'Setup a specific build display name')
Expand All @@ -255,7 +171,6 @@ void setupPromoteJob(String jobFolder, KogitoJobType jobType) {
env('REPO_NAME', 'kogito-runtimes')
env('PROPERTIES_FILE_NAME', 'deployment.properties')

env('RELEASE', jobType == KogitoJobType.RELEASE)
env('JENKINS_EMAIL_CREDS_ID', "${JENKINS_EMAIL_CREDS_ID}")

env('GIT_AUTHOR', "${GIT_AUTHOR_NAME}")
Expand Down
24 changes: 6 additions & 18 deletions .ci/jenkins/dsl/test.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
#!/bin/bash -e

TEMP_DIR=`mktemp -d`

branch=$1
author=$2

if [ -z $branch ]; then
branch='main'
fi

if [ -z $author ]; then
author='kiegroup'
fi

echo "----- Cloning pipelines repo from ${author} on branch ${branch}"
git clone --single-branch --branch ${branch} https://github.com/${author}/kogito-pipelines.git $TEMP_DIR

echo '----- Launching seed tests'
${TEMP_DIR}/dsl/seed/scripts/seed_test.sh ${TEMP_DIR}
file=$(mktemp)
# For more usage of the script, use ./test.sh -h
# TODO to update before merge
curl -o ${file} https://raw.githubusercontent.com/radtriste/kogito-pipelines/split_nightly_jobs/dsl/seed/scripts/seed_test.sh
chmod u+x ${file}
${file} $@
6 changes: 6 additions & 0 deletions .ci/jenkins/scripts/update-version/git_stage_files.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void execute(def pipelinesCommon) {
echo 'Hello from Git Stage Files script'
githubscm.findAndStageNotIgnoredFiles('pom.xml')
}

return this
14 changes: 14 additions & 0 deletions .ci/jenkins/scripts/update-version/init.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
void execute(def pipelinesCommon) {
echo 'Hello from init script'
if (pipelinesCommon.isRelease() || pipelinesCommon.isCreatePR()) {
// Verify version is set
assert pipelinesCommon.getKogitoVersion()

if (pipelinesCommon.isRelease()) {
// Verify if on right release branch
assert pipelinesCommon.getGitBranch() == util.getReleaseBranchFromVersion(pipelinesCommon.getKogitoVersion())
}
}
}

return this
6 changes: 6 additions & 0 deletions .ci/jenkins/scripts/update-version/main.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void execute(def pipelinesCommon) {
maven.mvnVersionsSet(pipelinesCommon.getDefaultMavenCommand(), pipelinesCommon.getKogitoVersion(), !pipelinesCommon.isRelease())
maven.mvnSetVersionProperty(pipelinesCommon.getDefaultMavenCommand(), 'version.org.kie', pipelinesCommon.getDroolsVersion())
}

return this
2 changes: 1 addition & 1 deletion .github/workflows/jenkins-tests-PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
java-version: 11

- name: Test DSL
run: cd .ci/jenkins/dsl && ./test.sh
run: cd .ci/jenkins/dsl && ./test.sh -b ${{ github.head_ref }} -o ${{ github.event.pull_request.user.login }} -t ${{ github.base_ref }} -a ${{ github.event.base.user.login }}

0 comments on commit 9b8686b

Please sign in to comment.