Skip to content

Commit

Permalink
KOGITO-9676 CI: Promote call setup-branch job
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste committed Aug 3, 2023
1 parent 5828d30 commit 4a69af5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 109 deletions.
112 changes: 7 additions & 105 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
import org.jenkinsci.plugins.workflow.libs.Library
@Library('jenkins-pipeline-shared-libraries')_

import org.kie.jenkins.MavenCommand

deployProperties = [:]
pipelineProperties = [:]

pipeline {
agent {
label 'kie-rhel8 && docker && !built-in'
}

tools {
maven env.BUILD_MAVEN_TOOL
jdk env.BUILD_JDK_TOOL
label 'rhel8 && !built-in'
}

options {
timestamps()
timeout(time: 180, unit: 'MINUTES')
timeout(time: 60, 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}")

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

stages {
Expand All @@ -45,19 +30,14 @@ pipeline {

readDeployProperties()

if (isRelease()) {
// Verify version is set and if on right release branch
assert getProjectVersion()
assert getDroolsVersion()
assert getBuildBranch() == util.getReleaseBranchFromVersion(getProjectVersion())
}
assert getProjectVersion()
assert getDroolsVersion()
assert getBuildBranch() == util.getReleaseBranchFromVersion(getProjectVersion())
}
}
}

stage('Merge deploy PR and tag') {
when {
expression { return isRelease() }
}
steps {
script {
dir(getRepoName()) {
Expand All @@ -68,10 +48,8 @@ pipeline {
}
}
}

stage('Create release') {
when {
expression { return isRelease() }
}
steps {
script {
dir(getRepoName()) {
Expand All @@ -85,37 +63,6 @@ pipeline {
}
}
}
stage('Set next snapshot version') {
when {
expression { return isRelease() }
}
steps {
script {
dir('pr') {
checkoutRepo()
githubscm.createBranch(getSnapshotBranch())

maven.mvnVersionsSet(getMavenCommand(), getSnapshotVersion(), true)
maven.mvnSetVersionProperty(getMavenCommand(), 'version.org.kie', getDroolsSnapshotVersion())

// Need artifacts available locally
getMavenCommand().withProperty('quickly').run('clean install')
maven.mvnSetVersionProperty(getMavenCommand(getWorkflowCommonDeploymentRelativePath()), "data-index-ephemeral.image", "${getCurrentNightlyImage()}" )
commitAndCreatePR()
}
dir(getRepoName()) {
sh "git checkout ${getBuildBranch()}"
mergeAndPush(getPipelinePrLink())

if (shouldDeployToRepository()) {
runMavenDeploy()
} else {
echo 'Testing environment and no specific deploy repository given => no deployment'
}
}
}
}
}
}
post {
unsuccessful {
Expand Down Expand Up @@ -176,10 +123,6 @@ String getParamOrDeployProperty(String paramKey, String deployPropertyKey) {
// Getter / Setter
//////////////////////////////////////////////////////////////////////////////

boolean shouldDeployToRepository() {
return env.MAVEN_DEPLOY_REPOSITORY || getGitAuthor() == 'kiegroup'
}

boolean isRelease() {
return env.RELEASE ? env.RELEASE.toBoolean() : false
}
Expand All @@ -196,10 +139,6 @@ String getDroolsVersion() {
return getParamOrDeployProperty('DROOLS_VERSION', 'drools.version')
}

String getSnapshotVersion() {
return util.getNextVersion(getProjectVersion(), 'micro')
}

String getDroolsSnapshotVersion() {
return util.getNextVersion(getDroolsVersion(), 'micro')
}
Expand All @@ -224,18 +163,6 @@ String getDeployPrLink() {
return getDeployProperty("${getRepoName()}.pr.link")
}

String getPipelinePrLink() {
return pipelineProperties["${getRepoName()}.pr.link"]
}

void setPipelinePrLink(String value) {
pipelineProperties["${getRepoName()}.pr.link"] = value
}

String getSnapshotBranch() {
return "${getSnapshotVersion().toLowerCase()}-${env.PR_BRANCH_HASH}"
}

//////////////////////////////////////////////////////////////////////////////
// Git
//////////////////////////////////////////////////////////////////////////////
Expand All @@ -260,15 +187,6 @@ void tagLatest() {
}
}

void commitAndCreatePR() {
def commitMsg = "[${getBuildBranch()}] Update project version to ${getSnapshotVersion()}"
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it should be merged automatically."

githubscm.commitChanges(commitMsg, { githubscm.findAndStageNotIgnoredFiles('pom.xml') })
githubscm.pushObject('origin', getSnapshotBranch(), getGitAuthorCredsID())
setPipelinePrLink(githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID()))
}

MavenCommand getMavenCommand(String directory = '') {
mvnCmd = new MavenCommand(this, ['-fae', '-ntp'])
.withSettingsXmlId("${env.MAVEN_SETTINGS_CONFIG_FILE_ID}")
Expand All @@ -281,19 +199,3 @@ MavenCommand getMavenCommand(String directory = '') {
}
return mvnCmd
}

void runMavenDeploy() {
mvnCmd = getMavenCommand()
if (env.MAVEN_DEPLOY_REPOSITORY) {
mvnCmd.withDeployRepository(env.MAVEN_DEPLOY_REPOSITORY)
}
mvnCmd.skipTests(true).run('clean deploy')
}

String getWorkflowCommonDeploymentRelativePath() {
return "quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment"
}

String getCurrentNightlyImage() {
return "quay.io/kiegroup/kogito-data-index-ephemeral-nightly:${util.getMajorMinorVersion(getProjectVersion())}"
}
24 changes: 20 additions & 4 deletions .ci/jenkins/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jenkinsci.plugins.workflow.libs.Library
import org.kie.jenkins.MavenCommand

droolsRepo = 'drools'
dataIndexEphemeralImageName = 'quay.io/kiegroup/kogito-data-index-ephemeral'

pipeline {
agent {
Expand Down Expand Up @@ -62,10 +63,10 @@ pipeline {
script {
maven.mvnVersionsSet(getMavenCommand(getRepoName()).withProperty('full'), getKogitoVersion(), true)
maven.mvnSetVersionProperty(getMavenCommand(getRepoName()), 'version.org.kie', getDroolsVersion())
if (!isMainBranch()) {
def path = "${getRepoName()}/quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/pom.xml"
sh "sed -i -r 's|<(data-index-ephemeral\\.image)>(.*):.*|<\\1>\\2:${getMajorMinorKogitoVersion()}</\\1>|' $path"
}

// Need artifacts available locally
getMavenCommand(getRepoName()).withProperty('quickly').run('clean install')
maven.mvnSetVersionProperty(getMavenCommand(getRepoName()).withOptions(['-pl :kogito-quarkus-workflow-common-deployment']), 'data-index-ephemeral.image', getDataIndexEphemeralImage())
}
}
}
Expand Down Expand Up @@ -158,3 +159,18 @@ String getMajorMinorKogitoVersion() {
boolean isMainBranch() {
return env.IS_MAIN_BRANCH?.toBoolean()
}

String getWorkflowCommonDeploymentRelativePath() {
return 'quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment'
}

String getDataIndexEphemeralImage() {
if (isMainBranch()) {
return "${dataIndexEphemeralImageName}-nightly:latest"
}
String version = getKogitoVersion()
if (version.endsWith('-SNAPSHOT')) {
return "${dataIndexEphemeralImageName}-nightly:${util.getMajorMinorVersion(version)}"
}
return "${dataIndexEphemeralImageName}:${util.getMajorMinorVersion(version)}"
}

0 comments on commit 4a69af5

Please sign in to comment.