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

NO-ISSUE: Jenkins jobs updates and fixes for Apache 10 release #3125

Merged
merged 7 commits into from
Oct 7, 2024
112 changes: 67 additions & 45 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ imageUtils = null

pipeline {
agent {
docker {
docker {
image env.AGENT_DOCKER_BUILDER_IMAGE
args env.AGENT_DOCKER_BUILDER_ARGS
label util.avoidFaultyNodes()
Expand All @@ -52,7 +52,6 @@ pipeline {
OPTAPLANNER_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}")

PR_BRANCH_HASH = "${util.generateHash(10)}"

}

stages {
Expand Down Expand Up @@ -103,7 +102,7 @@ pipeline {

stage('Prepare for PR') {
when {
expression { return isRelease() || isCreatePr() }
expression { return isCreatePr() }
}
steps {
script {
Expand Down Expand Up @@ -144,19 +143,15 @@ pipeline {
.withProperty('maven.test.failure.ignore', true)
.withProperty('operator.image.build')
.skipTests(params.SKIP_TESTS)
def Closure mavenRunClosure = {
configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]) {
mavenCommand.withSettingsXmlFile(MAVEN_SETTINGS_FILE).run("clean $installOrDeploy")
}
}

if (isRelease()) {
release.gpgImportKeyFromStringWithoutPassword(getReleaseGpgSignKeyCredsId())
releaseUtils.gpgImportKeyFromStringWithoutPassword(getReleaseGpgSignKeyCredsId())
mavenCommand.withProfiles(['apache-release'])
mavenRunClosure()
} else {
mavenRunClosure()
}

configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]) {
mavenCommand.withSettingsXmlFile(MAVEN_SETTINGS_FILE).run("clean $installOrDeploy")
}
}
if (isRelease()) {
updateAntoraYaml(optaplannerFolder)
Expand All @@ -176,12 +171,16 @@ pipeline {
stage('Build Quickstarts') {
steps {
script {
configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){
getOptaplannerQuickstartsMavenCommand()
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')]) {
getOptaplannerQuickstartsMavenCommand()
.withProperty('maven.test.failure.ignore', true)
.skipTests(params.SKIP_TESTS)
.withSettingsXmlFile(MAVEN_SETTINGS_FILE)
.withProperty('apache.repository.username', REPOSITORY_USER)
.withProperty('apache.repository.password', REPOSITORY_TOKEN)
.run('clean install')
}
}
}
}
Expand All @@ -197,7 +196,7 @@ pipeline {

stage('Create PRs') {
when {
expression { return isRelease() || isCreatePr() }
expression { return isCreatePr() }
}
steps {
script {
Expand All @@ -217,6 +216,18 @@ pipeline {
}
}

stage('Commit and Create Tag') {
when {
expression { return isRelease() }
}
steps {
script {
commitAndCreateTag(optaplannerFolder, getBuildBranch())
commitAndCreateTag(quickstartsFolder, getQuickStartsBranch())
}
}
}

stage('Push a temporary operator image to a registry') {
when {
expression { return isRelease() }
Expand Down Expand Up @@ -255,19 +266,28 @@ pipeline {
void sendErrorNotification() {
if (params.SEND_NOTIFICATION) {
String additionalInfo = "**[${getBuildBranch()}] Optaplanner - Deploy**"
mailer.sendMarkdownTestSummaryNotification("CI failures", [env.OPTAPLANNER_CI_EMAIL_TO], additionalInfo)
mailer.sendMarkdownTestSummaryNotification('CI failures', [env.OPTAPLANNER_CI_EMAIL_TO], additionalInfo)
} else {
echo 'No notification sent per configuration'
}
}

List getIntegrationTestProfiles() {
return params.SKIP_INTEGRATION_TESTS ? [] : ['integration-tests']
}

void updateQuickstartsVersions() {
maven.mvnSetVersionProperty(getOptaplannerQuickstartsMavenCommand(), 'version.org.optaplanner', getProjectVersion())
maven.mvnVersionsUpdateParentAndChildModules(getOptaplannerQuickstartsMavenCommand(), getProjectVersion(), !isRelease())
maven.mvnVersionsUpdateParent(getOptaplannerQuickstartsMavenCommand(), getProjectVersion(), !isRelease())

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')]) {
maven.mvnVersionsUpdateChildModules(
getOptaplannerQuickstartsMavenCommand()
.withSettingsXmlFile(MAVEN_SETTINGS_FILE)
.withProperty('apache.repository.username', REPOSITORY_USER)
.withProperty('apache.repository.password', REPOSITORY_TOKEN),
!isRelease()
)
}
}

gradleVersionsUpdate(quickstartsFolder, getProjectVersion())

if (isRelease()) {
Expand All @@ -279,6 +299,7 @@ void updateQuickstartsVersions() {
'cat', returnStdout: true)
}
}

if (isCreatePr()) {
dir(quickstartsFolder) {
// TODO: Remove the exclusion after the kubernetes demo is migrated to 9.
Expand Down Expand Up @@ -335,6 +356,20 @@ void prepareForPR(String folder) {
}
}

void commitAndCreateTag(String folder, String buildBranch) {
dir(folder) {
def commitMsg = "[${buildBranch}] Update project version to ${getProjectVersion()}"
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges(commitMsg, {
githubscm.findAndStageNotIgnoredFiles('pom.xml')
githubscm.findAndStageNotIgnoredFiles('build.gradle')
githubscm.findAndStageNotIgnoredFiles('antora.yml')
})
githubscm.tagRepository(getGitTagName())
githubscm.pushRemoteTag('origin', getGitTagName(), getGitAuthorPushCredsId())
}
}

void commitAndCreatePR(String folder, String repo, String buildBranch) {
dir(folder) {
def commitMsg = "[${buildBranch}] Update project version to ${getProjectVersion()}"
Expand Down Expand Up @@ -385,36 +420,19 @@ MavenCommand getOptaplannerQuickstartsMavenCommand() {
* Builds the parent modules and the BOM so that project depending on these artifacts can resolve.
*/
void mavenCleanInstallOptaPlannerParents() {
configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){
getOptaplannerMavenCommand()
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')]) {
getOptaplannerMavenCommand()
.skipTests(true)
.withOptions(['-U', '-pl org.optaplanner:optaplanner-build-parent,org.optaplanner:optaplanner-bom', '-am'])
.withSettingsXmlFile(MAVEN_SETTINGS_FILE)
.withProperty('apache.repository.username', REPOSITORY_USER)
.withProperty('apache.repository.password', REPOSITORY_TOKEN)
.run('clean install')
}
}
}

void runMavenDeploy(MavenCommand mvnCmd, String localDeploymentId = '') {
mvnCmd = mvnCmd.clone()

if (localDeploymentId) {
mvnCmd.withLocalDeployFolder(getLocalDeploymentFolder(localDeploymentId))
} else if (env.MAVEN_DEPLOY_REPOSITORY) {
mvnCmd.withDeployRepository(env.MAVEN_DEPLOY_REPOSITORY)
}

configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_CONFIG_FILE_ID, variable: 'MAVEN_SETTINGS_FILE')]){
mvnCmd
.withSettingsXmlFile(MAVEN_SETTINGS_FILE)
.skipTests(true)
.run('clean deploy')
}
}

String getMavenRepoZipUrl() {
return "${params.MAVEN_DEPLOY_REPOSITORY.replaceAll('/content/', '/service/local/').replaceFirst('/*$', '')}/content-compressed"
}

// Getters and Setters of params/properties

boolean shouldDeployToRepository() {
Expand Down Expand Up @@ -532,4 +550,8 @@ String getReleaseGpgSignKeyCredsId() {

String getReleaseGpgSignPassphraseCredsId() {
return env.RELEASE_GPG_SIGN_PASSPHRASE_CREDS_ID
}
}

String getGitTagName() {
return params.GIT_TAG_NAME
}
4 changes: 2 additions & 2 deletions .ci/jenkins/config/branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ cloud:
release:
gpg:
sign:
key-credentials-id: 'GPG_KEY'
passphrase-credentials-id: ''
key_credentials_id: GPG_KEY_FILE
passphrase_credentials_id: ''
jenkins:
email_creds_id: OPTAPLANNER_CI_NOTIFICATION_EMAILS
agent:
Expand Down
11 changes: 4 additions & 7 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,14 @@ void setupProjectReleaseJob() {

GIT_BRANCH_NAME: "${GIT_BRANCH}",
GIT_AUTHOR: "${GIT_AUTHOR_NAME}",

DEFAULT_STAGING_REPOSITORY: "${MAVEN_NEXUS_STAGING_PROFILE_URL}",
ARTIFACTS_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
OPTAPLANNER_LATEST_STREAM: "${GIT_MAIN_BRANCH}"
])
KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
parameters {
stringParam('RESTORE_FROM_PREVIOUS_JOB', '', 'URL to a previous stopped release job which needs to be continued')

stringParam('OPTAPLANNER_VERSION', '', 'Project version of OptaPlanner and its examples to release as Major.minor.micro')
stringParam('OPTAPLANNER_RELEASE_BRANCH', '', '(optional) Use to override the release branch name deduced from the OPTAPLANNER_VERSION')
stringParam('RELEASE_VERSION', '', 'Project version of OptaPlanner and its examples to release as Major.minor.micro')

stringParam('DROOLS_VERSION', '', '(optional) Drools version to be set to the project before releasing the artifacts.')
stringParam('GIT_TAG_NAME', '', 'Git tag to create. i.e.: 10.0.0-rc1')

booleanParam('SKIP_TESTS', false, 'Skip all tests')
}
Expand Down Expand Up @@ -370,6 +365,8 @@ void setupDeployJob(JobType jobType, String envName = '') {
stringParam('OPERATOR_IMAGE_REGISTRY_TOKEN_CREDENTIALS_ID', "${CLOUD_IMAGE_REGISTRY_TOKEN_CREDENTIALS_ID}", 'Image registry token credentials id.')
stringParam('OPERATOR_IMAGE_NAMESPACE', "${CLOUD_IMAGE_NAMESPACE}", 'Operator image namespace to use to deploy image.')
stringParam('OPERATOR_IMAGE_TAG', '', 'Image tag to use to deploy the operator image. OptaPlanner project version if not set.')

stringParam('GIT_TAG_NAME', '', 'Optional if not RELEASE. Tag to be created in the repository')
}
}
}
Expand Down
Loading
Loading