| @Library('jenkins-pipeline-shared-libraries')_ |
| |
| helper = null |
| |
| pipeline { |
| agent { |
| label 'kie-rhel8 && kie-mem16g && !built-in' |
| } |
| |
| options { |
| timeout(time: 3, unit: 'HOURS') |
| timestamps() |
| } |
| |
| tools { |
| go 'golang-1.19' |
| } |
| |
| environment { |
| KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") |
| } |
| |
| stages { |
| stage('Setup pipeline') { |
| steps { |
| script { |
| helper = load '.ci/jenkins/scripts/helper.groovy' |
| helper.initPipeline() |
| } |
| } |
| } |
| stage('Initialize') { |
| steps { |
| script { |
| helper.cleanGoPath() |
| |
| helper.updateDisplayName() |
| helper.checkoutRepo() |
| |
| if (helper.isRelease()) { |
| // Verify version is set and if on right release branch |
| assert helper.getProjectVersion() |
| assert helper.getBuildBranch() == util.getReleaseBranchFromVersion(helper.getProjectVersion()) |
| } |
| |
| // Verify we have the connectivity to Openshift |
| openshift.loginOpenshift() |
| } |
| } |
| post { |
| success { |
| script { |
| properties.add('git.branch', helper.getBuildBranch()) |
| properties.add('git.author', helper.getGitAuthor()) |
| properties.add('project.version', helper.getProjectVersion()) |
| properties.add('release', helper.isRelease()) |
| } |
| } |
| } |
| } |
| |
| stage('Prepare for PR') { |
| when { |
| expression { return helper.isRelease() } |
| } |
| steps { |
| script { |
| githubscm.createBranch(helper.getPRBranch()) |
| } |
| } |
| } |
| |
| stage('Update version') { |
| when { |
| expression { return helper.getProjectVersion() } |
| } |
| steps { |
| script { |
| sh "make bump-version new_version=${helper.getProjectVersion()}" |
| } |
| } |
| } |
| |
| stage('Test Operator') { |
| when { |
| expression { |
| return helper.shouldLaunchTests() |
| } |
| } |
| steps { |
| sh 'make test' |
| } |
| post { |
| unsuccessful { |
| script { |
| util.archiveConsoleLog() |
| } |
| } |
| } |
| } |
| |
| stage('Build Operator') { |
| steps { |
| sh "make container-build BUILDER=${env.CONTAINER_ENGINE} IMG=${getBuiltImage()}" |
| } |
| post { |
| unsuccessful { |
| script { |
| util.archiveConsoleLog() |
| } |
| } |
| } |
| } |
| |
| stage('Run e2e tests') { |
| when { |
| expression { |
| return helper.shouldLaunchTests() |
| } |
| } |
| environment { |
| MINIKUBE_VERSION = '1.28.0' |
| KUBERNETES_VERSION = '1.23.14' |
| } |
| steps { |
| script { |
| // Start minikube |
| minikube.minikubeMemory = '12g' |
| minikube.start() |
| |
| minikube.waitForMinikubeStarted() |
| minikube.waitForMinikubeRegistry() |
| |
| // Push image to minikube |
| String minikubeImageName = "${minikube.getImageRegistry()}/${env.OPERATOR_IMAGE_NAME}:${getOperatorVersion()}" |
| container.tagImage(getBuiltImage(), minikubeImageName) |
| container.pushImage(minikubeImageName) |
| sh """ |
| export OPERATOR_IMAGE_NAME=${minikubeImageName} |
| make test-e2e |
| kubectl get pods -A |
| """ |
| } |
| } |
| post { |
| always { |
| script { |
| minikube.stop() |
| } |
| } |
| } |
| } |
| |
| stage('Push to registry') { |
| when { |
| expression { return !params.SKIP_DEPLOY } |
| } |
| steps { |
| script { |
| helper.loginRegistry() |
| |
| container.tagImage(getBuiltImage(), helper.getImageFullTag(env.OPERATOR_IMAGE_NAME)) |
| container.pushImage(helper.getImageFullTag(env.OPERATOR_IMAGE_NAME)) |
| |
| if (helper.isDeployLatestTag()) { |
| String finalFullImage = helper.getImageFullTag(env.OPERATOR_IMAGE_NAME, defaultImageParamsPrefix, 'latest') |
| container.tagImage(getBuiltImage(), finalFullImage) |
| container.pushImage(finalFullImage) |
| } |
| |
| String reducedTag = helper.getReducedTag() |
| if (reducedTag) { |
| String finalFullImage = helper.getImageFullTag(env.OPERATOR_IMAGE_NAME, defaultImageParamsPrefix, reducedTag) |
| container.tagImage(getBuiltImage(), finalFullImage) |
| container.pushImage(finalFullImage) |
| } |
| |
| // Store image deployment information |
| properties.add(helper.getImageRegistryProperty(), helper.getImageRegistry()) |
| properties.add(helper.getImageNamespaceProperty(), helper.getImageNamespace()) |
| properties.add(helper.getImageNamePrefixProperty(), helper.getImageNamePrefix()) |
| properties.add(helper.getImageNameSuffixProperty(), helper.getImageNameSuffix()) |
| properties.add(helper.getImageTagProperty(), helper.getImageTag()) |
| } |
| } |
| } |
| |
| stage('Create PR') { |
| when { |
| expression { return helper.isRelease() } |
| } |
| steps { |
| script { |
| if (githubscm.isThereAnyChanges()) { |
| String prMsg = "[${helper.getBuildBranch()}] Update project version to ${helper.getProjectVersion()}" |
| def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it shoud be merged automatically." |
| githubscm.commitChanges(prMsg, { |
| sh ''' |
| git add . |
| git reset -- go.mod |
| git reset -- go.sum |
| ''' |
| }) |
| githubscm.pushObject('origin', helper.getPRBranch(), helper.getGitAuthorCredsID()) |
| prLink = githubscm.createPR(prMsg, prBody, helper.getBuildBranch(), helper.getGitAuthorCredsID()) |
| properties.add("${helper.getRepoName()}.pr.link", prLink) |
| |
| properties.add("${helper.getRepoName()}.pr.source.uri", "https://github.com/${helper.getGitAuthorCredsID()}/${helper.getRepoName()}") |
| properties.add("${helper.getRepoName()}.pr.source.ref", helper.getPRBranch()) |
| properties.add("${helper.getRepoName()}.pr.target.uri", "https://github.com/${helper.getGitAuthor()}/${helper.getRepoName()}") |
| properties.add("${helper.getRepoName()}.pr.target.ref", helper.getBuildBranch()) |
| } else { |
| println '[WARN] no changes to commit' |
| } |
| } |
| } |
| } |
| } |
| post { |
| always { |
| script { |
| properties.writeToFile(env.PROPERTIES_FILE_NAME) |
| archiveArtifacts(artifacts: env.PROPERTIES_FILE_NAME) |
| } |
| } |
| unsuccessful { |
| sendNotification() |
| } |
| cleanup { |
| script { |
| helper.cleanGoPath() |
| util.cleanNode(containerEngine) |
| } |
| } |
| } |
| } |
| |
| void sendNotification() { |
| if (params.SEND_NOTIFICATION) { |
| mailer.sendMarkdownTestSummaryNotification('Deploy', "[${helper.getBuildBranch()}] Kogito Serverless Operator", [env.KOGITO_CI_EMAIL_TO]) |
| } else { |
| echo 'No notification sent per configuration' |
| } |
| } |
| |
| String getOperatorVersion() { |
| return sh(script: 'source ./hack/env.sh > /dev/null && echo $(getOperatorVersion)', returnStdout: true).trim() |
| } |
| |
| String getBuiltImage() { |
| return "quay.io/kiegroup/${env.OPERATOR_IMAGE_NAME}:${getOperatorVersion()}" |
| } |