This is an automated email from the ASF dual-hosted git repository.

rantunes pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git


The following commit(s) were added to refs/heads/main by this push:
     new 6e22d4d766 Drools weekly job (#5661)
6e22d4d766 is described below

commit 6e22d4d766c5c4b40aa496d5f6c910b9efb08725
Author: Rodrigo Antunes <[email protected]>
AuthorDate: Fri Jan 26 09:12:03 2024 -0300

    Drools weekly job (#5661)
---
 .ci/jenkins/Jenkinsfile.weekly.deploy  | 246 +++++++++++++++++++++++++++++++++
 .ci/jenkins/dsl/jobs.groovy            |  58 +++++++-
 .ci/jenkins/project/Jenkinsfile.weekly | 164 ++++++++++++++++++++++
 3 files changed, 467 insertions(+), 1 deletion(-)

diff --git a/.ci/jenkins/Jenkinsfile.weekly.deploy 
b/.ci/jenkins/Jenkinsfile.weekly.deploy
new file mode 100644
index 0000000000..e9b3c87878
--- /dev/null
+++ b/.ci/jenkins/Jenkinsfile.weekly.deploy
@@ -0,0 +1,246 @@
+import org.jenkinsci.plugins.workflow.libs.Library
+@Library('jenkins-pipeline-shared-libraries')_
+
+import org.kie.jenkins.MavenCommand
+import org.kie.jenkins.MavenStagingHelper
+
+deployProperties = [:]
+
+pipeline {
+    agent {
+        docker {
+            image env.AGENT_DOCKER_BUILDER_IMAGE
+            args env.AGENT_DOCKER_BUILDER_ARGS
+        }
+    }
+
+    options {
+        timestamps()
+        timeout(time: 180, unit: 'MINUTES')
+    }
+
+    environment {
+        DROOLS_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}")
+
+        MAVEN_DEPLOY_LOCAL_DIR = "/tmp/maven_deploy_dir"
+    }
+
+    stages {
+        stage('Initialize') {
+            steps {
+                script {
+                    cleanWs(disableDeferredWipeout: true)
+
+                    if (params.DISPLAY_NAME) {
+                        currentBuild.displayName = params.DISPLAY_NAME
+                    }
+
+                    dir(getRepoName()) {
+                        checkoutRepo()
+                    }
+
+                    env.PROJECT_VERSION = 
maven.mvnGetVersionProperty(getMavenCommand(), 'project.version')
+                }
+            }
+            post {
+                success {
+                    script {
+                        setDeployPropertyIfNeeded('git.branch', 
getBuildBranch())
+                        setDeployPropertyIfNeeded('git.author', getGitAuthor())
+                        setDeployPropertyIfNeeded('project.version', 
getProjectVersion())
+                    }
+                }
+            }
+        }
+
+        stage('Update project version') {
+            steps {
+                script {
+                    maven.mvnVersionsSet(
+                        getMavenCommand(),
+                        getProjectVersion(),
+                        true
+                    )
+                }
+            }
+        }
+
+        stage('Build & Test & Deploy locally') {
+            steps {
+                script {
+                    runMavenLocalDeploy(params.SKIP_TESTS)
+                }
+            }
+            post {
+                always {
+                    script {
+                        saveReports()
+                        util.archiveConsoleLog()
+                    }
+                }
+            }
+        }
+
+        stage('Upload artifacts to given repository') {
+            when {
+                expression { return shouldDeployToRepository() }
+            }
+            steps {
+                script {
+                    withCredentials([usernamePassword(credentialsId: 
env.MAVEN_REPO_CREDS_ID, usernameVariable: 'REPOSITORY_USER', passwordVariable: 
'REPOSITORY_TOKEN')]) {
+                        configFileProvider([configFile(fileId: 
env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]) {
+                            getMavenCommand()
+                                .withSettingsXmlFile(MAVEN_SETTINGS_FILE)
+                                .withProperty('wagon.source', 
"file://${getLocalDeploymentFolder()}")
+                                .withProperty('wagon.target', 
env.MAVEN_DEPLOY_REPOSITORY)
+                                .withProperty('wagon.targetId', 
'apache-snapshots-repository')
+                                
.withProperty('apache.snapshot.repository.username', REPOSITORY_USER)
+                                
.withProperty('apache.snapshot.repository.password', REPOSITORY_TOKEN)
+                                
.run("org.codehaus.mojo:wagon-maven-plugin:2.0.2:merge-maven-repos")
+                        }
+                    }
+                }
+            }
+        }
+
+        stage('Create and push a new tag') {
+            steps {
+                script {
+                    projectVersion = getProjectVersion(false)
+                    dir(getRepoName()) {
+                        
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
+                        githubscm.tagRepository(projectVersion)
+                        githubscm.pushRemoteTag('origin', projectVersion, 
getGitAuthorPushCredsId())
+                    }
+                }
+            }
+        }
+    }
+    post {
+        always {
+            script {
+                def propertiesStr = deployProperties.collect { entry ->  
"${entry.key}=${entry.value}" }.join('\n')
+                writeFile(text: propertiesStr, file: PROPERTIES_FILE_NAME)
+                archiveArtifacts(artifacts: PROPERTIES_FILE_NAME)
+            }
+        }
+        unsuccessful {
+            sendNotification()
+        }
+        cleanup {
+            script {
+                util.cleanNode()
+            }
+        }
+    }
+}
+
+void saveReports() {
+    junit testResults: '**/target/surefire-reports/**/*.xml, 
**/target/failsafe-reports/**/*.xml, **/target/invoker-reports/**/TEST-*.xml', 
allowEmptyResults: true
+}
+
+void checkoutRepo() {
+    deleteDir()
+    checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), 
getBuildBranch(), false, getGitAuthorCredsId()))
+    // need to manually checkout branch since on a detached branch after 
checkout command
+    sh "git checkout ${getBuildBranch()}"
+    checkoutDatetime = getCheckoutDatetime()
+    if (checkoutDatetime) {
+        sh "git checkout `git rev-list -n 1 --before=\"${checkoutDatetime}\" 
${getBuildBranch()}`"
+    }
+}
+
+void sendNotification() {
+    if (params.SEND_NOTIFICATION) {
+        mailer.sendMarkdownTestSummaryNotification('Weekly Deploy', 
"[${getBuildBranch()}] Drools", [env.DROOLS_CI_EMAIL_TO])
+    } else {
+        echo 'No notification sent per configuration'
+    }
+}
+
+boolean shouldDeployToRepository() {
+    return env.MAVEN_DEPLOY_REPOSITORY && env.MAVEN_REPO_CREDS_ID && 
getGitAuthor() == 'apache'
+}
+
+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 getPRBranch() {
+    return params.DROOLS_PR_BRANCH
+}
+
+String getGitAuthorCredsId() {
+    return env.GIT_AUTHOR_CREDS_ID
+}
+
+String getGitAuthorPushCredsId() {
+    return env.GIT_AUTHOR_PUSH_CREDS_ID
+}
+
+void setDeployPropertyIfNeeded(String key, def value) {
+    if (value) {
+        deployProperties[key] = value
+    }
+}
+
+MavenCommand getMavenCommand(String directory = '') {
+    directory = directory ?: getRepoName()
+    def mvnCmd = new MavenCommand(this, ['-fae', '-ntp'])
+                .withOptions(env.BUILD_MVN_OPTS ? [ env.BUILD_MVN_OPTS ] : [])
+                .inDirectory(directory)
+    if (!isMainStream()) { // Workaround as enforcer rules may not be fixed on 
other streams
+        mvnCmd.withProperty('enforcer.skip')
+    } else {
+        mvnCmd.withProperty('full')
+    }
+    return mvnCmd
+}
+
+void runMavenLocalDeploy(boolean skipTests = true) {
+    mvnCmd = getMavenCommand()
+    mvnCmd.withLocalDeployFolder(getLocalDeploymentFolder())
+
+    configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, 
variable: 'MAVEN_SETTINGS_FILE')]){
+        mvnCmd.withProperty('maven.test.failure.ignore', true)
+            .withOptions(env.DROOLS_BUILD_MVN_OPTS ? [ 
env.DROOLS_BUILD_MVN_OPTS ] : [])
+            .withOptions(env.BUILD_MVN_OPTS_CURRENT ? [ 
env.BUILD_MVN_OPTS_CURRENT ] : [])
+            .skipTests(skipTests)
+            .withSettingsXmlFile(MAVEN_SETTINGS_FILE)
+            .run('clean deploy')
+    }
+}
+
+String getLocalDeploymentFolder() {
+    return "${env.MAVEN_DEPLOY_LOCAL_DIR}/${getRepoName()}"
+}
+
+boolean isMainStream() {
+    return env.DROOLS_STREAM == 'main'
+}
+
+String getCheckoutDatetime() {
+    return params.GIT_CHECKOUT_DATETIME
+}
+
+String getProjectVersionDate() {
+    def projectVersionDate = (getCheckoutDatetime() =~ 
/(\d{4}-\d{2}-\d{2})/)[0][0]
+    return projectVersionDate.replace('-', '')
+}
+
+String getProjectVersion(boolean keepSnapshotSuffix = true) {
+    def projectVersion = env.PROJECT_VERSION
+    if (keepSnapshotSuffix) {
+        return projectVersion.replace("-SNAPSHOT", 
"-${getProjectVersionDate()}-SNAPSHOT")
+    }
+    return projectVersion.replace("-SNAPSHOT", "-${getProjectVersionDate()}")
+}
diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy
index 105577d4fe..08fee13e9a 100644
--- a/.ci/jenkins/dsl/jobs.groovy
+++ b/.ci/jenkins/dsl/jobs.groovy
@@ -34,6 +34,9 @@ createProjectSetupBranchJob()
 // Nightly jobs
 setupProjectNightlyJob()
 
+// Weekly jobs
+setupProjectWeeklyJob()
+
 // Release jobs
 setupProjectReleaseJob()
 setupProjectPostReleaseJob()
@@ -80,6 +83,23 @@ void setupProjectNightlyJob() {
     }
 }
 
+void setupProjectWeeklyJob() {
+    def jobParams = JobParamsUtils.getBasicJobParams(this, '0-weekly', 
JobType.OTHER, "${jenkins_path_project}/Jenkinsfile.weekly", 'Drools Weekly')
+    jobParams.triggers = [cron : '0 3 * * 0']
+    jobParams.env.putAll([
+        JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",
+
+        GIT_BRANCH_NAME: "${GIT_BRANCH}",
+
+        DROOLS_STREAM: Utils.getStream(this),
+    ])
+    KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
+        parameters {
+            booleanParam('SKIP_TESTS', false, 'Skip all tests')
+        }
+    }
+}
+
 void setupProjectReleaseJob() {
     def jobParams = JobParamsUtils.getBasicJobParams(this, '0-drools-release', 
JobType.RELEASE, "${jenkins_path_project}/Jenkinsfile.release", 'Drools/Kogito 
Artifacts Release')
     jobParams.env.putAll([
@@ -214,6 +234,9 @@ setupSpecificBuildChainNightlyJob('sonarcloud', 
setupSonarProjectKeyEnv(nightlyJ
 setupDeployJob(JobType.RELEASE)
 setupPromoteJob(JobType.RELEASE)
 
+// Weekly deploy job
+setupWeeklyDeployJob()
+
 // Tools job
 if (isMainStream()) {
     KogitoJobUtils.createQuarkusUpdateToolsJob(this, 'drools', [
@@ -335,4 +358,37 @@ void setupPromoteJob(JobType jobType) {
             booleanParam('SEND_NOTIFICATION', false, 'In case you want the 
pipeline to send a notification on CI channel for this run.')
         }
     }
-}
\ No newline at end of file
+}
+
+void setupWeeklyDeployJob() {
+    def jobParams = JobParamsUtils.getBasicJobParams(this, 
'drools.weekly-deploy', JobType.OTHER, 
"${jenkins_path}/Jenkinsfile.weekly.deploy", 'Drools Weekly Deploy')
+    JobParamsUtils.setupJobParamsAgentDockerBuilderImageConfiguration(this, 
jobParams)
+    jobParams.env.putAll([
+        PROPERTIES_FILE_NAME: 'deployment.properties',
+        JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",
+
+        GIT_AUTHOR: "${GIT_AUTHOR_NAME}",
+        GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
+        GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",
+
+        MAVEN_SETTINGS_CONFIG_FILE_ID: "${MAVEN_SETTINGS_FILE_ID}",
+        MAVEN_DEPENDENCIES_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
+        MAVEN_DEPLOY_REPOSITORY: "${MAVEN_ARTIFACTS_UPLOAD_REPOSITORY_URL}",
+        MAVEN_REPO_CREDS_ID: "${MAVEN_ARTIFACTS_UPLOAD_REPOSITORY_CREDS_ID}",
+
+        DROOLS_STREAM: Utils.getStream(this),
+    ])
+    KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
+        parameters {
+            stringParam('DISPLAY_NAME', '', 'Setup a specific build display 
name')
+
+            stringParam('BUILD_BRANCH_NAME', "${GIT_BRANCH}", 'Set the Git 
branch to checkout')
+
+            booleanParam('SKIP_TESTS', false, 'Skip tests')
+
+            stringParam('GIT_CHECKOUT_DATETIME', '', 'Git checkout date and 
time - (Y-m-d H:i)')
+
+            booleanParam('SEND_NOTIFICATION', false, 'In case you want the 
pipeline to send a notification on CI channel for this run.')
+        }
+    }
+}
diff --git a/.ci/jenkins/project/Jenkinsfile.weekly 
b/.ci/jenkins/project/Jenkinsfile.weekly
new file mode 100644
index 0000000000..41a79934d8
--- /dev/null
+++ b/.ci/jenkins/project/Jenkinsfile.weekly
@@ -0,0 +1,164 @@
+import org.jenkinsci.plugins.workflow.libs.Library
+
+@Library('jenkins-pipeline-shared-libraries')_
+
+// Deploy jobs
+DROOLS_DEPLOY = 'drools.weekly-deploy'
+// KIE_JPMML_INTEGRATION_DEPLOY = 'kie-jpmml-integration.build-and-deploy' // 
Commented as not migrated for now
+
+// 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 = [:]
+
+FAILED_STAGES = [:]
+UNSTABLE_STAGES = [:]
+
+// Should be multibranch pipeline
+pipeline {
+    agent {
+        label 'ubuntu'
+    }
+
+    options {
+        timeout(time: 360, unit: 'MINUTES')
+    }
+
+    environment {
+        DROOLS_CI_EMAIL = credentials("${JENKINS_EMAIL_CREDS_ID}")
+
+        // Use branch name in weekly tag as we may have parallel main and 
release branch builds
+        WEEKLY_TAG = """${getBuildBranch()}-${sh(
+                returnStdout: true,
+                script: 'date -u "+%Y-%m-%d"'
+            ).trim()}"""
+    }
+
+    stages {
+        stage('Initialize') {
+            steps {
+                script {
+                    echo "weekly tag is ${env.WEEKLY_TAG}"
+
+                    currentBuild.displayName = env.WEEKLY_TAG
+                }
+            }
+        }
+        stage('Build & Deploy Drools') {
+            steps {
+                script {
+                    def buildParams = getDefaultBuildParams()
+                    addSkipTestsParam(buildParams)
+                    addSkipIntegrationTestsParam(buildParams)
+
+                    buildJob(DROOLS_DEPLOY, buildParams)
+                }
+            }
+            post {
+                failure {
+                    addFailedStage(DROOLS_DEPLOY)
+                }
+            }
+        }
+    }
+    post {
+        unsuccessful {
+            sendPipelineErrorNotification()
+        }
+    }
+}
+
+def buildJob(String jobName, List buildParams, String jobKey = jobName) {
+    echo "[${jobKey}] Build ${jobName} with params ${buildParams}"
+
+    def job = build(job: "${jobName}", wait: true, parameters: buildParams, 
propagate: false)
+    JOBS[jobKey] = job
+
+    // Set Unstable if job did not succeed
+    if (!isJobSucceeded(jobKey)) {
+        addUnstableStage(jobKey)
+        unstable("Job ${jobName} finished with result ${job.result}")
+    }
+    return job
+}
+
+def getJob(String jobKey) {
+    return JOBS[jobKey]
+}
+
+String getJobUrl(String jobKey) {
+    echo "getJobUrl for ${jobKey}"
+    return getJob(jobKey)?.absoluteUrl ?: ''
+}
+
+boolean isJobSucceeded(String jobKey) {
+    return getJob(jobKey)?.result == 'SUCCESS'
+}
+
+void addFailedStage(String jobKey = '') {
+    FAILED_STAGES.put("${env.STAGE_NAME}", jobKey)
+}
+void addUnstableStage(String jobKey = '') {
+    UNSTABLE_STAGES.put("${env.STAGE_NAME}", jobKey)
+}
+
+void sendPipelineErrorNotification() {
+    String bodyMsg = "Kogito weekly job #${env.BUILD_NUMBER} was: 
${currentBuild.currentResult}"
+
+    paramsStr = ''
+    if (params.SKIP_TESTS) {
+        paramsStr += '\n- Tests skipped'
+    }
+    bodyMsg += paramsStr ? "\n\nConfiguration:${paramsStr}" : '\n'
+
+    if (FAILED_STAGES.size() > 0) {
+        bodyMsg += '\nFailed stages: \n- '
+        bodyMsg += FAILED_STAGES.collect { "${it.key} => 
${getJobUrl(it.value)}" }.join('\n- ')
+    }
+    bodyMsg += '\n'
+    if (UNSTABLE_STAGES.size() > 0) {
+        bodyMsg += '\nUnstable stages: \n- '
+        bodyMsg += UNSTABLE_STAGES.collect { "${it.key} => 
${getJobUrl(it.value)}" }.join('\n- ')
+    }
+    bodyMsg += '\n'
+    bodyMsg += "\nPlease look here: ${env.BUILD_URL}"
+    emailext body: bodyMsg, subject: "[${getBuildBranch()}][d] Full Pipeline",
+                to: env.DROOLS_CI_EMAIL
+}
+
+List getDefaultBuildParams() {
+    List params = []
+    addStringParam(params, 'DISPLAY_NAME', "${env.WEEKLY_TAG}")
+    addStringParam(params, 'GIT_CHECKOUT_DATETIME', getCheckoutDatetime())
+    addBooleanParam(params, 'SEND_NOTIFICATION', true)
+
+    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 buildParams, String key, String value) {
+    buildParams.add(string(name: key, value: value))
+}
+
+void addBooleanParam(List buildParams, String key, boolean value) {
+    buildParams.add(booleanParam(name: key, value: value))
+}
+
+String getBuildBranch() {
+    return env.GIT_BRANCH_NAME
+}
+
+String getCurrentDate() {
+    return sh(returnStdout: true, script: 'date -u "+%Y-%m-%d"').trim()
+}
+
+String getCheckoutDatetime() {
+    return getCurrentDate() + ' 02:00' // Cut-off 02:00AM
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to