Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kie-issues#821: Kogito-runtimes weekly job #3361

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 257 additions & 0 deletions .ci/jenkins/Jenkinsfile.weekly.deploy
Original file line number Diff line number Diff line change
@@ -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()
}
34 changes: 34 additions & 0 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ setupSpecificBuildChainNightlyJob('native', nightlyJobParamsGetter)
setupReleaseDeployJob()
setupReleasePromoteJob()

// Weekly deploy job
setupWeeklyDeployJob()

// Tools job
if (isMainStream()) {
KogitoJobUtils.createQuarkusVersionUpdateToolsJobForCurrentRepo(this, [
Expand Down Expand Up @@ -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.')
}
}
}
6 changes: 3 additions & 3 deletions .ci/jenkins/tests/setup_pipeline_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
cd $TEMP_DIR/jenkins-pipeline-shared-libraries && mvn clean install -DskipTests
4 changes: 2 additions & 2 deletions .github/workflows/pr-jenkins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading