From 6c677c52f94bb8cbd64e4ccbc63bda24808b2cf0 Mon Sep 17 00:00:00 2001 From: Rodrigo Antunes Date: Mon, 22 Jan 2024 09:10:17 -0300 Subject: [PATCH 1/2] Kogito Runtimes weekly job --- .ci/jenkins/Jenkinsfile.weekly.deploy | 257 ++++++++++++++++++++++++++ .ci/jenkins/dsl/jobs.groovy | 34 ++++ 2 files changed, 291 insertions(+) create mode 100644 .ci/jenkins/Jenkinsfile.weekly.deploy diff --git a/.ci/jenkins/Jenkinsfile.weekly.deploy b/.ci/jenkins/Jenkinsfile.weekly.deploy new file mode 100644 index 00000000000..7a43f30f798 --- /dev/null +++ b/.ci/jenkins/Jenkinsfile.weekly.deploy @@ -0,0 +1,257 @@ +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() + } + + env.PROJECT_VERSION = maven.mvnGetVersionProperty(getMavenCommand(), 'project.version') + } + } + 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', + getDroolsVersion() + ) + } + } + } + + 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 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) // Conflict somehow with Python testing. If `skipTests={anyvalue}` is set, then exec plugin is not executed ... + .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()}") +} + +String getDroolsVersion() { + return getProjectVersion() +} diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index e80ff2533ca..bec830b9819 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -111,6 +111,9 @@ setupSpecificBuildChainNightlyJob('native', nightlyJobParamsGetter) setupReleaseDeployJob() setupReleasePromoteJob() +// Weekly deploy job +setupWeeklyDeployJob() + // Tools job if (isMainStream()) { KogitoJobUtils.createQuarkusVersionUpdateToolsJobForCurrentRepo(this, [ @@ -236,3 +239,34 @@ void setupReleasePromoteJob() { } } } + +void setupWeeklyDeployJob() { + def jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-runtimes.weekly-deploy', JobType.OTHER, "${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.') + } + } +} From 4b33dfb2835b0db1b369968d1577979b0aad0b22 Mon Sep 17 00:00:00 2001 From: Rodrigo Antunes Date: Mon, 22 Jan 2024 16:16:22 -0300 Subject: [PATCH 2/2] Fix github CI --- .ci/jenkins/tests/setup_pipeline_env.sh | 6 +++--- .github/workflows/pr-jenkins.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.ci/jenkins/tests/setup_pipeline_env.sh b/.ci/jenkins/tests/setup_pipeline_env.sh index 8943da04e0d..e6f471ac293 100755 --- a/.ci/jenkins/tests/setup_pipeline_env.sh +++ b/.ci/jenkins/tests/setup_pipeline_env.sh @@ -5,13 +5,13 @@ author=$1 branch=$2 if [ -z $author ]; then - author='kiegroup' + author='apache' fi if [ -z $branch ]; then branch='main' fi -git clone --single-branch --branch $branch https://github.com/${author}/jenkins-pipeline-shared-libraries.git $TEMP_DIR +git clone --single-branch --branch $branch https://github.com/${author}/incubator-kie-kogito-pipelines.git $TEMP_DIR -cd $TEMP_DIR && mvn clean install -DskipTests \ No newline at end of file +cd $TEMP_DIR/jenkins-pipeline-shared-libraries && mvn clean install -DskipTests \ No newline at end of file diff --git a/.github/workflows/pr-jenkins.yml b/.github/workflows/pr-jenkins.yml index 1955cbfdfab..e1076aedfda 100644 --- a/.github/workflows/pr-jenkins.yml +++ b/.github/workflows/pr-jenkins.yml @@ -25,8 +25,8 @@ jobs: - name: Checkout shared libraries uses: actions/checkout@v4 with: - repository: kiegroup/jenkins-pipeline-shared-libraries - path: shared-libs + repository: apache/incubator-kie-kogito-pipelines + path: jenkins-pipeline-shared-libraries - name: Set up JDK 8 uses: actions/setup-java@v3