From 9b8686b34cc05e4c862c1fe1d523a87a1a4d7a0e Mon Sep 17 00:00:00 2001 From: radtriste Date: Mon, 20 Sep 2021 16:44:35 +0200 Subject: [PATCH] Split nightly job --- .ci/jenkins/dsl/jobs.groovy | 123 +++--------------- .ci/jenkins/dsl/test.sh | 24 +--- .../update-version/git_stage_files.groovy | 6 + .../scripts/update-version/init.groovy | 14 ++ .../scripts/update-version/main.groovy | 6 + .github/workflows/jenkins-tests-PR.yml | 2 +- 6 files changed, 52 insertions(+), 123 deletions(-) create mode 100644 .ci/jenkins/scripts/update-version/git_stage_files.groovy create mode 100644 .ci/jenkins/scripts/update-version/init.groovy create mode 100644 .ci/jenkins/scripts/update-version/main.groovy diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index 04946198764..dfc6ed77356 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -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, @@ -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', @@ -53,7 +45,7 @@ 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 @@ -61,73 +53,30 @@ if (Utils.isMainBranch(this)) { } // 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 { @@ -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) @@ -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') } @@ -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}") @@ -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}") @@ -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') @@ -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}") diff --git a/.ci/jenkins/dsl/test.sh b/.ci/jenkins/dsl/test.sh index 3bdf692c7b2..4320139911f 100755 --- a/.ci/jenkins/dsl/test.sh +++ b/.ci/jenkins/dsl/test.sh @@ -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} $@ \ No newline at end of file diff --git a/.ci/jenkins/scripts/update-version/git_stage_files.groovy b/.ci/jenkins/scripts/update-version/git_stage_files.groovy new file mode 100644 index 00000000000..11e870ff3d9 --- /dev/null +++ b/.ci/jenkins/scripts/update-version/git_stage_files.groovy @@ -0,0 +1,6 @@ +void execute(def pipelinesCommon) { + echo 'Hello from Git Stage Files script' + githubscm.findAndStageNotIgnoredFiles('pom.xml') +} + +return this diff --git a/.ci/jenkins/scripts/update-version/init.groovy b/.ci/jenkins/scripts/update-version/init.groovy new file mode 100644 index 00000000000..88cdeb80c2e --- /dev/null +++ b/.ci/jenkins/scripts/update-version/init.groovy @@ -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 diff --git a/.ci/jenkins/scripts/update-version/main.groovy b/.ci/jenkins/scripts/update-version/main.groovy new file mode 100644 index 00000000000..67292269a78 --- /dev/null +++ b/.ci/jenkins/scripts/update-version/main.groovy @@ -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 diff --git a/.github/workflows/jenkins-tests-PR.yml b/.github/workflows/jenkins-tests-PR.yml index 01b1ae40f89..c9541cae83e 100644 --- a/.github/workflows/jenkins-tests-PR.yml +++ b/.github/workflows/jenkins-tests-PR.yml @@ -48,4 +48,4 @@ jobs: java-version: 11 - name: Test DSL - run: cd .ci/jenkins/dsl && ./test.sh \ No newline at end of file + 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 }}