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

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


The following commit(s) were added to refs/heads/kie-issues_821 by this push:
     new a4a03d3e27 Weekly job fixes
a4a03d3e27 is described below

commit a4a03d3e2735e3984ce3f69d6e991cf21bd04d6b
Author: Rodrigo Antunes <[email protected]>
AuthorDate: Thu Jan 18 15:44:13 2024 -0300

    Weekly job fixes
---
 .ci/jenkins/Jenkinsfile.weekly.deploy | 95 +++++++++++++++++++++++------------
 .ci/jenkins/dsl/jobs.groovy           |  4 +-
 2 files changed, 66 insertions(+), 33 deletions(-)

diff --git a/.ci/jenkins/Jenkinsfile.weekly.deploy 
b/.ci/jenkins/Jenkinsfile.weekly.deploy
index 6c5f260eba..e9b3c87878 100644
--- a/.ci/jenkins/Jenkinsfile.weekly.deploy
+++ b/.ci/jenkins/Jenkinsfile.weekly.deploy
@@ -8,7 +8,7 @@ deployProperties = [:]
 
 pipeline {
     agent {
-        docker { 
+        docker {
             image env.AGENT_DOCKER_BUILDER_IMAGE
             args env.AGENT_DOCKER_BUILDER_ARGS
         }
@@ -38,6 +38,8 @@ pipeline {
                     dir(getRepoName()) {
                         checkoutRepo()
                     }
+
+                    env.PROJECT_VERSION = 
maven.mvnGetVersionProperty(getMavenCommand(), 'project.version')
                 }
             }
             post {
@@ -46,41 +48,27 @@ pipeline {
                         setDeployPropertyIfNeeded('git.branch', 
getBuildBranch())
                         setDeployPropertyIfNeeded('git.author', getGitAuthor())
                         setDeployPropertyIfNeeded('project.version', 
getProjectVersion())
-                        setDeployPropertyIfNeeded('release', isRelease())
                     }
                 }
             }
         }
 
         stage('Update project version') {
-            when {
-                expression { return getProjectVersion() }
-            }
             steps {
                 script {
-                    configFileProvider([configFile(fileId: 
env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){
-                        maven.mvnVersionsSet(
-                            
getMavenCommand().withSettingsXmlFile(MAVEN_SETTINGS_FILE),
-                            getProjectVersion(),
-                            true
-                        )
-                    }
+                    maven.mvnVersionsSet(
+                        getMavenCommand(),
+                        getProjectVersion(),
+                        true
+                    )
                 }
             }
         }
 
-        stage('Build & Test') {
+        stage('Build & Test & Deploy locally') {
             steps {
                 script {
-                    configFileProvider([configFile(fileId: 
env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){
-                        getMavenCommand()
-                            .withOptions(env.DROOLS_BUILD_MVN_OPTS ? [ 
env.DROOLS_BUILD_MVN_OPTS ] : [])
-                            .withOptions(env.BUILD_MVN_OPTS_CURRENT ? [ 
env.BUILD_MVN_OPTS_CURRENT ] : [])
-                            .withProperty('maven.test.failure.ignore', true)
-                            .skipTests(params.SKIP_TESTS)
-                            .withSettingsXmlFile(MAVEN_SETTINGS_FILE)
-                            .run('clean install')
-                    }
+                    runMavenLocalDeploy(params.SKIP_TESTS)
                 }
             }
             post {
@@ -93,10 +81,37 @@ pipeline {
             }
         }
 
-        stage('Deploy locally') {
+        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 {
-                    runMavenLocalDeploy()
+                    projectVersion = getProjectVersion(false)
+                    dir(getRepoName()) {
+                        
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
+                        githubscm.tagRepository(projectVersion)
+                        githubscm.pushRemoteTag('origin', projectVersion, 
getGitAuthorPushCredsId())
+                    }
                 }
             }
         }
@@ -129,6 +144,10 @@ void checkoutRepo() {
     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() {
@@ -140,7 +159,7 @@ void sendNotification() {
 }
 
 boolean shouldDeployToRepository() {
-    return env.MAVEN_DEPLOY_REPOSITORY || getGitAuthor() == 'apache'
+    return env.MAVEN_DEPLOY_REPOSITORY && env.MAVEN_REPO_CREDS_ID && 
getGitAuthor() == 'apache'
 }
 
 String getRepoName() {
@@ -156,10 +175,6 @@ String getBuildBranch() {
     return params.BUILD_BRANCH_NAME
 }
 
-String getProjectVersion() {
-    return params.PROJECT_VERSION
-}
-
 String getPRBranch() {
     return params.DROOLS_PR_BRANCH
 }
@@ -191,14 +206,15 @@ MavenCommand getMavenCommand(String directory = '') {
     return mvnCmd
 }
 
-void runMavenLocalDeploy() {
+void runMavenLocalDeploy(boolean skipTests = true) {
     mvnCmd = getMavenCommand()
     mvnCmd.withLocalDeployFolder(getLocalDeploymentFolder())
 
     configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, 
variable: 'MAVEN_SETTINGS_FILE')]){
-        mvnCmd.skipTests(true)
+        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')
     }
@@ -211,3 +227,20 @@ String getLocalDeploymentFolder() {
 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 943f0c2a79..179cbbf36b 100644
--- a/.ci/jenkins/dsl/jobs.groovy
+++ b/.ci/jenkins/dsl/jobs.groovy
@@ -341,7 +341,7 @@ void setupPromoteJob(JobType jobType) {
 }
 
 void setupWeeklyDeployJob() {
-    def jobParams = JobParamsUtils.getBasicJobParams(this, 
'drools-weekly-deploy', JobType.OTHER, 
"${jenkins_path}/Jenkinsfile.weekly.deploy", 'Drools Weekly Deploy')
+    def jobParams = JobParamsUtils.getBasicJobParams(this, 
'drools.weekly-deploy', JobType.OTHER, 
"${jenkins_path}/Jenkinsfile.weekly.deploy", 'Drools Weekly Deploy')
     jobParams.env.putAll([
         PROPERTIES_FILE_NAME: 'deployment.properties',
         JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",
@@ -365,7 +365,7 @@ void setupWeeklyDeployJob() {
 
             booleanParam('SKIP_TESTS', false, 'Skip tests')
 
-            stringParam('PROJECT_VERSION', '', 'Project Version to deploy')
+            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.')
         }


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

Reply via email to