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-kogito-apps.git
The following commit(s) were added to refs/heads/main by this push:
new d44179b15 Kogito Apps weekly job (#1965)
d44179b15 is described below
commit d44179b1503424c6e1852bb4913ae8d11d3b515b
Author: Rodrigo Antunes <[email protected]>
AuthorDate: Fri Jan 26 09:12:27 2024 -0300
Kogito Apps weekly job (#1965)
---
.ci/jenkins/Jenkinsfile.weekly-deploy | 247 ++++++++++++++++++++++++++++++++++
.ci/jenkins/dsl/jobs.groovy | 38 +++++-
2 files changed, 284 insertions(+), 1 deletion(-)
diff --git a/.ci/jenkins/Jenkinsfile.weekly-deploy
b/.ci/jenkins/Jenkinsfile.weekly-deploy
new file mode 100644
index 000000000..8ef332621
--- /dev/null
+++ b/.ci/jenkins/Jenkinsfile.weekly-deploy
@@ -0,0 +1,247 @@
+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: 600, unit: 'MINUTES')
+ }
+
+ // parameters {
+ // For parameters, check into ./dsl/jobs.groovy file
+ // }
+
+ environment {
+ // Static env is defined into ./dsl/jobs.groovy file
+
+ KOGITO_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.parent.version')
+ }
+ }
+ post {
+ success {
+ script {
+ setDeployPropertyIfNeeded('git.branch',
getBuildBranch())
+ setDeployPropertyIfNeeded('git.author', getGitAuthor())
+ setDeployPropertyIfNeeded('project.version',
getProjectVersion())
+ }
+ }
+ }
+ }
+ stage('Update project version') {
+ steps {
+ script {
+ maven.mvnVersionsUpdateParentAndChildModules(
+ 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: 'deployment.properties')
+ archiveArtifacts(artifacts: 'deployment.properties')
+ }
+ }
+ unsuccessful {
+ sendNotification()
+ }
+ cleanup {
+ script {
+ util.cleanNode()
+ }
+ }
+ }
+}
+
+void sendNotification() {
+ if (params.SEND_NOTIFICATION) {
+ mailer.sendMarkdownTestSummaryNotification('Weekly Deploy',
"[${getBuildBranch()}] Kogito Apps", [env.KOGITO_CI_EMAIL_TO])
+ } else {
+ echo 'No notification sent per configuration'
+ }
+}
+
+void saveReports() {
+ // Remove `node_modules` to avoid heap space issues with junit command
thereafter
+ // Related to https://github.com/jenkinsci/junit-plugin/issues/478 and
https://github.com/jenkinsci/junit-plugin/issues/467
+ sh 'find . -type d -name node_modules -exec rm -rf {} \\; || true'
+ junit(testResults: '**/junit.xml, **/target/surefire-reports/**/*.xml,
**/target/failsafe-reports/**/*.xml, **/target/invoker-reports/**/*.xml',
allowEmptyResults: true)
+ archiveArtifacts artifacts:
'**/*.log,**/cypress/screenshots/**,**/cypress/videos/**', allowEmptyArchive:
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()}`"
+ }
+}
+
+boolean isSpecificArtifactsUpload() {
+ return env.MAVEN_DEPLOY_REPOSITORY && env.MAVEN_REPO_CREDS_ID
+}
+
+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 getGitAuthorCredsId() {
+ return env.GIT_AUTHOR_CREDS_ID
+}
+
+String getGitAuthorPushCredsId() {
+ return env.GIT_AUTHOR_PUSH_CREDS_ID
+}
+
+String getBuildBranch() {
+ return params.BUILD_BRANCH_NAME
+}
+
+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)
+ .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.BUILD_MVN_OPTS_CURRENT ? [
env.BUILD_MVN_OPTS_CURRENT ] : [])
+ .withOptions(env.KOGITO_APPS_BUILD_MVN_OPTS ? [
env.KOGITO_APPS_BUILD_MVN_OPTS ] : [])
+ .skipTests(skipTests)
+ .withSettingsXmlFile(MAVEN_SETTINGS_FILE)
+ .run('clean deploy')
+ }
+}
+
+String getLocalDeploymentFolder() {
+ return "${env.MAVEN_DEPLOY_LOCAL_DIR}/${getRepoName()}"
+}
+
+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 ec1c7743e..0d9199121 100644
--- a/.ci/jenkins/dsl/jobs.groovy
+++ b/.ci/jenkins/dsl/jobs.groovy
@@ -138,6 +138,9 @@ setupSpecificBuildChainNightlyJob('native',
nightlyJobParamsGetter)
setupReleaseDeployJob()
setupReleasePromoteJob()
+// Weekly deploy job
+setupWeeklyDeployJob()
+
// Update Optaplanner tools job
if (isMainStream()) {
KogitoJobUtils.createVersionUpdateToolsJob(this, 'kogito-apps',
'Optaplanner', [
@@ -277,4 +280,37 @@ void setupReleasePromoteJob() {
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.')
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]