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 46d31a6 commit c0584e7
Showing 1 changed file with 11 additions and 105 deletions.
116 changes: 11 additions & 105 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,14 @@ pipeline {
label 'kie-rhel8 && docker && !built-in'
}

tools {
maven env.BUILD_MAVEN_TOOL
jdk env.BUILD_JDK_TOOL
}

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)}"

NODE_OPTIONS = '--max_old_space_size=4096'
}

Expand All @@ -47,59 +34,34 @@ pipeline {

readDeployProperties()

if (isRelease()) {
// Verify version is set and if on right release branch
assert getProjectVersion()

assert getBuildBranch() == util.getReleaseBranchFromVersion(getProjectVersion())
}

setupCypressEnv('9.7.0')
assert getProjectVersion()
assert getBuildBranch() == util.getReleaseBranchFromVersion(getProjectVersion())
}
}
}

stage('Merge deploy PR and tag') {
when {
expression { return isRelease() }
}
steps {
script {
dir(getRepoName()) {
checkoutRepo()
mergeAndPush(getDeployPrLink())
tagLatest()
if(githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsID())) {
githubscm.deleteRelease(getGitTag(), getGitAuthorCredsID())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTag(getGitTag()), getGitAuthorCredsID())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsID())
}
}
}
}
stage('Set apps next snapshot version') {
when {
expression { return isRelease() }
}

stage('Create release') {
steps {
script {
dir('pr') {
checkoutRepo()
githubscm.createBranch(getSnapshotBranch())

maven.mvnVersionsUpdateParentAndChildModules(getMavenCommand(), getSnapshotVersion(), true)

commitAndCreatePR()
}
dir(getRepoName()) {
sh "git checkout ${getBuildBranch()}"
mergeAndPush(getPipelinePrLink())

if (shouldDeployToRepository()) {
runMavenDeploy()
} else {
echo 'Testing environment and no specific deploy repository given => no deployment'
checkoutRepo()
if (githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsID())) {
githubscm.deleteRelease(getGitTag(), getGitAuthorCredsID())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTag(getGitTag()), getGitAuthorCredsID())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsID())
}
}
}
Expand All @@ -125,12 +87,6 @@ void sendNotification() {
}
}

void setupCypressEnv(String cypressVersion) {
if (env.CYPRESS_BINARY_URL) {
env.CYPRESS_INSTALL_BINARY = "${CYPRESS_BINARY_URL}/cypress-${cypressVersion}.zip"
}
}

//////////////////////////////////////////////////////////////////////////////
// Deployment properties
//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -170,14 +126,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
}

String getRepoName() {
return env.REPO_NAME
}
Expand All @@ -186,10 +134,6 @@ String getProjectVersion() {
return getParamOrDeployProperty('PROJECT_VERSION', 'project.version')
}

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

String getGitTag() {
return params.GIT_TAG != '' ? params.GIT_TAG : getProjectVersion()
}
Expand All @@ -210,18 +154,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 @@ -245,29 +177,3 @@ void tagLatest() {
githubscm.tagLocalAndRemoteRepository('origin', getGitTag(), getGitAuthorCredsID(), env.BUILD_TAG, true)
}
}

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

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

MavenCommand getMavenCommand() {
mvnCmd = new MavenCommand(this, ['-fae', '-ntp'])
.withSettingsXmlId(env.MAVEN_SETTINGS_CONFIG_FILE_ID)
if (env.MAVEN_DEPENDENCIES_REPOSITORY) {
mvnCmd.withDependencyRepositoryInSettings('deps-repo', env.MAVEN_DEPENDENCIES_REPOSITORY)
}
return mvnCmd
}

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

0 comments on commit c0584e7

Please sign in to comment.