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

KOGITO-6959 Build chain deploy capability #732

Merged
merged 2 commits into from
Dec 9, 2022
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
46 changes: 41 additions & 5 deletions .ci/jenkins/Jenkinsfile.buildchain
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ timeoutValue = env.ADDITIONAL_TIMEOUT?.trim() ?: '180'
jdkTool = env.BUILD_JDK_TOOL
mavenTool = env.BUILD_MAVEN_TOOL

mavenDeployArtifacts = env.ENABLE_DEPLOY
mavenDeployRepository = env.MAVEN_DEPLOY_REPOSITORY ?: ''
mavenDeployRepositoryCredsId = env.MAVEN_DEPLOY_REPOSITORY_CREDS_ID ?: ''
mavenDeployLocalDir = env.MAVEN_DEPLOY_LOCAL_DIR ?: ''

buildChainType = env.BUILDCHAIN_TYPE?.trim() ?: 'pr'
buildChainProject = env.BUILDCHAIN_PROJECT?.trim()
defaultSettingsXmlId = isPRBuildChainType() || isFDBBuildChainType() ? 'kogito_pr_settings' : 'kogito_release_settings'
Expand Down Expand Up @@ -58,13 +63,22 @@ pipeline {
script {
sh 'printenv > env_props'
archiveArtifacts artifacts: 'env_props'

if (mavenDeployArtifacts) {
assert mavenDeployRepository : 'Please provide the maven deploy repository'
assert mavenDeployRepositoryCredsId : 'Please provide the maven deploy repository credentials'
}
}
}
}
stage('check space before build') {
steps {
script {
util.spaceLeft()
try {
util.spaceLeft()
} catch (err) {
echo "Error when checking the space on node ... ${err}"
}
}
}
}
Expand Down Expand Up @@ -131,14 +145,17 @@ pipeline {
}
steps {
script {
env.BUILD_MVN_OPTS = "${env.BUILD_MVN_OPTS ?: ''} -Dmaven.wagon.http.ssl.insecure=true -Dmaven.test.failure.ignore=true"
env.BUILD_MVN_OPTS_CURRENT = "${env.BUILD_MVN_OPTS_CURRENT ?: ''} ${getBuildMavenOptsCurrent()}"
echo "BUILD_MVN_OPTS_CURRENT = ${BUILD_MVN_OPTS_CURRENT}"
if (mavenDeployArtifacts) {
env.DEPLOY_MVN_OPTS = "${env.DEPLOY_MVN_OPTS ?: ''} -DaltDeploymentRepository=local::default::file://${getMavenDeployLocalDir()}"
echo "DEPLOY_MVN_OPTS = ${DEPLOY_MVN_OPTS}"
}

configFileProvider([configFile(fileId: settingsXmlId, variable: 'MAVEN_SETTINGS_FILE')]) {
withCredentials([string(credentialsId: 'kie-ci3-token', variable: 'GITHUB_TOKEN')]) {
env.BUILD_MVN_OPTS = "${env.BUILD_MVN_OPTS} -s ${MAVEN_SETTINGS_FILE}"
env.BUILD_MVN_OPTS = "${env.BUILD_MVN_OPTS ?: ''} -s ${MAVEN_SETTINGS_FILE} -Dmaven.wagon.http.ssl.insecure=true -Dmaven.test.failure.ignore=true"
echo "BUILD_MVN_OPTS = ${BUILD_MVN_OPTS}"
echo "BUILD_MVN_OPTS_CURRENT = ${BUILD_MVN_OPTS_CURRENT}"

sh "${getBuildChainCommandline(true)}"
}
Expand Down Expand Up @@ -176,6 +193,22 @@ pipeline {
}
}
}
stage('Upload artifacts to repository') {
when {
expression { return mavenDeployArtifacts }
}
tools {
jdk jdkTool
maven mavenTool
}
steps {
script {
// Upload to specific repository with credentials
String mavenDeployRepositoryZipUrl = "${mavenDeployRepository.replaceAll('/content/', '/service/local/').replaceFirst('/*$', '')}/content-compressed"
maven.uploadLocalArtifacts(mavenDeployRepositoryCredsId, getMavenDeployLocalDir(), mavenDeployRepositoryZipUrl)
}
}
}
stage('check space after build') {
steps {
script {
Expand Down Expand Up @@ -255,7 +288,6 @@ String getReproducer() {
${BUILD_MVN_OPTS_CURRENT ? "export BUILD_MVN_OPTS_CURRENT=${BUILD_MVN_OPTS_CURRENT}" : '\n'}
${getBuildChainCommandline()}


NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution
```
"""
Expand All @@ -265,3 +297,7 @@ String getRepoNameCamelCase(String repo) {
List words = repo.split('-') as List
return words.collect { it.isEmpty() ? it : it.substring(0, 1).toUpperCase() + it.substring(1).toLowerCase() }.join(' ')
}

String getMavenDeployLocalDir() {
return mavenDeployLocalDir ?: "${WORKSPACE}/maven_deploy_dir"
}
160 changes: 89 additions & 71 deletions .ci/jenkins/Jenkinsfile.nightly
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import org.jenkinsci.plugins.workflow.libs.Library

@Library('jenkins-pipeline-shared-libraries')_

// Deploy jobs
DROOLS_DEPLOY = 'drools-deploy'
RUNTIMES_DEPLOY = 'kogito-runtimes-deploy'
APPS_DEPLOY = 'kogito-apps-deploy'
EXAMPLES_DEPLOY = 'kogito-examples-deploy'
DROOLS_DEPLOY = 'drools.build-and-deploy'
RUNTIMES_DEPLOY = 'kogito-runtimes.build-and-deploy'
APPS_DEPLOY = 'kogito-apps.build-and-deploy'
EXAMPLES_DEPLOY = 'kogito-examples.build-and-deploy'
IMAGES_DEPLOY = 'kogito-images-deploy'
EXAMPLES_IMAGES_DEPLOY = 'kogito-examples-images-deploy'
OPERATOR_DEPLOY = 'kogito-operator-deploy'
Expand All @@ -28,7 +29,7 @@ promoteImageParamsPrefix = 'PROMOTE_IMAGE'
// Should be multibranch pipeline
pipeline {
agent {
label 'kie-rhel7 && !built-in'
label 'kie-rhel8 && !built-in'
}

options {
Expand All @@ -51,7 +52,7 @@ pipeline {
returnStdout: true,
script: 'date -u "+%Y-%m-%d"'
).trim()}"""
}
}

stages {
stage('Initialize') {
Expand All @@ -64,83 +65,92 @@ pipeline {
}
}

stage('Build & Deploy Drools') {
stage('Build & Deploy artifacts') {
when {
expression { return isArtifactsDeploy() }
}
steps {
script {
def buildParams = getDefaultBuildParams()
addSkipTestsParam(buildParams)
parallel {
stage('Build & Deploy Drools') {
steps {
script {
def buildParams = getDefaultBuildParams()
addSkipTestsParam(buildParams)
addSkipIntegrationTestsParam(buildParams)

// images and operator deploy testing will use older working artifacts if that one fails
buildJob(DROOLS_DEPLOY, buildParams)
}
}
post {
failure {
addFailedStage(DROOLS_DEPLOY)
// images and operator deploy testing will use older working artifacts if that one fails
buildJob(DROOLS_DEPLOY, buildParams)
}
}
post {
failure {
addFailedStage(DROOLS_DEPLOY)
}
}
}
}
}

stage('Build & Deploy Kogito Runtimes') {
when {
expression { return isArtifactsDeploy() }
}
steps {
script {
def buildParams = getDefaultBuildParams()
addSkipTestsParam(buildParams)
stage('Build & Deploy Kogito Runtimes') {
steps {
script {
def buildParams = getDefaultBuildParams()
addSkipTestsParam(buildParams)
addSkipIntegrationTestsParam(buildParams)

// images and operator deploy testing will use older working artifacts if that one fails
buildJob(RUNTIMES_DEPLOY, buildParams)
}
}
post {
failure {
addFailedStage(RUNTIMES_DEPLOY)
// images and operator deploy testing will use older working artifacts if that one fails
buildJob(RUNTIMES_DEPLOY, buildParams)
}
}
post {
failure {
addFailedStage(RUNTIMES_DEPLOY)
}
}
}
}
}

stage('Build & Deploy Kogito Apps') {
when {
expression { return isArtifactsDeploy() }
}
steps {
script {
def buildParams = getDefaultBuildParams()
addSkipTestsParam(buildParams)
stage('Build & Deploy Kogito Apps') {
steps {
script {
def buildParams = getDefaultBuildParams()
addSkipTestsParam(buildParams)
addSkipIntegrationTestsParam(buildParams)

// images and operator deploy testing will use older working artifacts if that one fails
buildJob(APPS_DEPLOY, buildParams)
}
}
post {
failure {
addFailedStage(APPS_DEPLOY)
// images and operator deploy testing will use older working artifacts if that one fails
buildJob(APPS_DEPLOY, buildParams)
}
}
post {
failure {
addFailedStage(APPS_DEPLOY)
}
}
}
}
}

stage('Build & Deploy Kogito Examples') {
when {
expression { return isArtifactsDeploy() }
}
steps {
script {
def buildParams = getDefaultBuildParams()
addSkipTestsParam(buildParams)
addBooleanParam(buildParams, 'UPDATE_NIGHTLY_BRANCH', true)

// images and operator deploy testing will use older working artifacts if that one fails
buildJob(EXAMPLES_DEPLOY, buildParams)
}
}
post {
failure {
addFailedStage(EXAMPLES_DEPLOY)
stage('Build & Deploy Kogito Examples') {
steps {
script {
def buildParams = getDefaultBuildParams()
addSkipTestsParam(buildParams)
addSkipIntegrationTestsParam(buildParams)

// images and operator deploy testing will use older working artifacts if that one fails
buildJob(EXAMPLES_DEPLOY, buildParams)

if (isJobSucceeded(EXAMPLES_DEPLOY) || isJobUnstable(EXAMPLES_DEPLOY)) {
// Update examples nightly branch
dir('kogito-examples') {
deleteDir()
checkout(githubscm.resolveRepository('kogito-examples', getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsID()))
String nightlyBranch = "nightly-${getBuildBranch()}"
githubscm.createBranch(nightlyBranch)
githubscm.pushObject('origin', nightlyBranch, getGitAuthorCredsID())
}
}
}
}
post {
failure {
addFailedStage(EXAMPLES_DEPLOY)
}
}
}
}
}
Expand Down Expand Up @@ -354,6 +364,10 @@ boolean isJobSucceeded(String jobKey) {
return getJob(jobKey)?.result == 'SUCCESS'
}

boolean isJobUnstable(String jobKey) {
return getJob(jobKey)?.result == 'UNSTABLE'
}

String getMandrelJobKey(String jobName) {
return "${jobName}-mandrel"
}
Expand Down Expand Up @@ -457,6 +471,10 @@ String getGitAuthor() {
return env.GIT_AUTHOR
}

String getGitAuthorCredsID() {
return env.GIT_AUTHOR_CREDS_ID
}

boolean isDeployImagesLatestTag() {
return getBuildBranch() == env.BRANCH_FOR_LATEST
}
Expand Down
15 changes: 15 additions & 0 deletions .ci/jenkins/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ pipeline {
addDroolsVersionParam(buildParams)
addKogitoVersionParam(buildParams)
buildJob('kogito-examples', buildParams)

if (isJobSucceeded('kogito-examples') || isJobUnstable('kogito-examples')) {
// Update examples nightly branch
dir('kogito-examples') {
deleteDir()
checkout(githubscm.resolveRepository('kogito-examples', getGitAuthor(), getBuildBranch(), false))
String nightlyBranch = "nightly-${getBuildBranch()}"
githubscm.createBranch(nightlyBranch)
githubscm.pushObject('origin', nightlyBranch, getGitAuthorCredsID())
}
}
}
}
post {
Expand Down Expand Up @@ -303,6 +314,10 @@ String getGitAuthor() {
return env.GIT_AUTHOR
}

String getGitAuthorCredsID() {
return env.GIT_AUTHOR_CREDS_ID
}

String getDroolsVersion() {
return params.DROOLS_VERSION ?: getVersionFromReleaseBranch(util.calculateTargetReleaseBranch(getBuildBranch(), 7))
}
Expand Down
2 changes: 2 additions & 0 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void createSetupBranchJob() {

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

IMAGE_REGISTRY_CREDENTIALS: "${CLOUD_IMAGE_REGISTRY_CREDENTIALS_NIGHTLY}",
IMAGE_REGISTRY: "${CLOUD_IMAGE_REGISTRY}",
Expand All @@ -123,6 +124,7 @@ void setupNightlyJob() {

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

IMAGE_REGISTRY_CREDENTIALS: "${CLOUD_IMAGE_REGISTRY_CREDENTIALS_NIGHTLY}",
IMAGE_REGISTRY: "${CLOUD_IMAGE_REGISTRY}",
Expand Down
Loading