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-kogito-runtimes.git
commit 209d9d95d21b8ab47809945b4ec5d94b94209f7e Author: Rodrigo Antunes <[email protected]> AuthorDate: Thu Jan 18 14:15:48 2024 -0300 Initial implementation of Kogito Runtimes weekly deploy job --- .ci/jenkins/Jenkinsfile.weekly.deploy | 251 ++++++++++++++++++++++++++++++++++ .ci/jenkins/dsl/jobs.groovy | 35 +++++ 2 files changed, 286 insertions(+) diff --git a/.ci/jenkins/Jenkinsfile.weekly.deploy b/.ci/jenkins/Jenkinsfile.weekly.deploy new file mode 100644 index 0000000000..70eccf4c5a --- /dev/null +++ b/.ci/jenkins/Jenkinsfile.weekly.deploy @@ -0,0 +1,251 @@ +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: 360, 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() + } + } + } + post { + success { + script { + dir(getRepoName()) { + setDeployPropertyIfNeeded('git.branch', getBuildBranch()) + setDeployPropertyIfNeeded('git.author', getGitAuthor()) + setDeployPropertyIfNeeded('project.version', getProjectVersion()) + setDeployPropertyIfNeeded('drools.version', getDroolsVersion()) + } + } + } + } + } + + stage('Update project version') { + steps { + script { + maven.mvnVersionsSet( + getMavenCommand(), + getProjectVersion(), + true + ) + + // Drools version is equal to the project version + maven.mvnSetVersionProperty( + getMavenCommand(), + 'version.org.kie', + getProjectVersion() + ) + } + } + } + + 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')]) { + new 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 saveReports() { + junit testResults: '**/target/surefire-reports/**/*.xml, **/target/failsafe-reports/**/*.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()}] Kogito Runtimes", [env.KOGITO_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 getGitAuthorCredsId() { + return env.GIT_AUTHOR_CREDS_ID +} + +String getGitAuthorPushCredsId() { + return env.GIT_AUTHOR_PUSH_CREDS_ID +} + +String getBuildBranch() { + return params.BUILD_BRANCH_NAME +} + +String getPRBranch() { + return params.KOGITO_PR_BRANCH +} + +void setDeployPropertyIfNeeded(String key, def value) { + if (value) { + deployProperties[key] = value + } +} + +MavenCommand getMavenCommand(String directory = '') { + directory = directory ?: getRepoName() + return new MavenCommand(this, ['-fae', '-ntp']) + .withOptions(env.BUILD_MVN_OPTS ? [ env.BUILD_MVN_OPTS ] : []) + .inDirectory(directory) + .withProperty('full') +} + +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_RUNTIMES_BUILD_MVN_OPTS ? [ env.KOGITO_RUNTIMES_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() { + date = (getCheckoutDatetime() =~ /(\d{4}-\d{2}-\d{2})/)[0][0] + return date.replace('-', '') +} + +String getProjectVersion(boolean keepSnapshotSuffix = true) { + version = maven.mvnGetVersionProperty(getMavenCommand(), 'project.version') + if (keepSnapshotSuffix) { + return version.replace("-SNAPSHOT", "-${getProjectVersionDate()}-SNAPSHOT") + } + return version.replace("-SNAPSHOT", "-${getProjectVersionDate()}") +} diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index e80ff2533c..569507bd79 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -111,6 +111,9 @@ setupSpecificBuildChainNightlyJob('native', nightlyJobParamsGetter) setupReleaseDeployJob() setupReleasePromoteJob() +// Weekly job +setupWeeklyDeployJob() + // Tools job if (isMainStream()) { KogitoJobUtils.createQuarkusVersionUpdateToolsJobForCurrentRepo(this, [ @@ -236,3 +239,35 @@ void setupReleasePromoteJob() { } } } + + +void setupWeeklyDeployJob() { + def jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-runtimes.weekly-deploy', JobType.RELEASE, "${jenkins_path}/Jenkinsfile.weekly.deploy", 'Kogito Runtimes Weekly Deploy') + JobParamsUtils.setupJobParamsAgentDockerBuilderImageConfiguration(this, jobParams) + jobParams.env.putAll([ + 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}", + ]) + 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') + + // Build&test information + 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]
