| @Library('jenkins-pipeline-shared-libraries')_ |
| |
| IMAGES = ['kogito-serverless-operator'] |
| |
| helper = null |
| |
| pipeline { |
| agent { |
| docker { |
| image env.AGENT_DOCKER_BUILDER_IMAGE |
| args env.AGENT_DOCKER_BUILDER_ARGS |
| label util.avoidFaultyNodes() |
| } |
| } |
| |
| options { |
| timeout(time: 120, unit: 'MINUTES') |
| timestamps() |
| } |
| |
| environment { |
| KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") |
| |
| PR_BRANCH_HASH = "${util.generateHash(10)}" |
| } |
| |
| stages { |
| stage('Setup pipeline') { |
| steps { |
| script { |
| helper = load '.ci/jenkins/scripts/helper.groovy' |
| helper.initPipeline() |
| } |
| } |
| } |
| stage('Initialize') { |
| steps { |
| script { |
| helper.updateDisplayName() |
| |
| properties.readFromUrl(helper.getDeployPropertiesFileUrl()) |
| |
| if (helper.isRelease()) { |
| // Verify version is set and if on right release branch |
| assert helper.getProjectVersion() |
| assert helper.getBuildBranch() == util.getReleaseBranchFromVersion(helper.getProjectVersion()) |
| } |
| |
| // Login old and new registries |
| helper.loginRegistry(baseImageParamsPrefix) |
| helper.loginRegistry(promoteImageParamsPrefix) |
| } |
| } |
| } |
| stage('Promote images') { |
| steps { |
| script { |
| for (String imageName : IMAGES) { |
| // Tag with given parameter tag |
| promoteImage(helper.getImageFullTag(imageName, baseImageParamsPrefix), helper.getImageFullTag(imageName, promoteImageParamsPrefix)) |
| |
| try { |
| promoteImage(helper.getImageFullTag(imageName, baseImageParamsPrefix), helper.getImageReducedTag(imageName, promoteImageParamsPrefix)) |
| } catch (err) { |
| echo 'Reduced tag cannot be applied' |
| } |
| |
| // Tag with `latest` tag if asked for as parameter |
| if (helper.isDeployLatestTag()) { |
| promoteImage(helper.getImageFullTag(imageName, baseImageParamsPrefix), helper.getImageFullTag(imageName, promoteImageParamsPrefix, 'latest')) |
| } |
| } |
| } |
| } |
| } |
| stage('Merge PR and create tags') { |
| when { |
| expression { return helper.isRelease() } |
| } |
| steps { |
| script { |
| dir(helper.getRepoName()) { |
| helper.checkoutRepo() |
| |
| // Merge PR |
| String prLink = properties.retrieve("${helper.getRepoName()}.pr.link") |
| if (prLink) { |
| githubscm.mergePR(prLink, helper.getGitAuthorPushCredsId()) |
| githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorPushCredsId()) |
| } |
| |
| // Tag api / container-builder |
| helper.createTag("api/${helper.getGitTag()}") |
| helper.createTag("container-builder/${helper.getGitTag()}") |
| |
| // Update api in workflowproj |
| dir('workflowproj') { |
| updateInternalGoModuleWithTag('api', "api/${helper.getGitTag()}") |
| } |
| sh 'make generate-all' |
| commitAndPush('origin', "[${helper.getBuildBranch()}] Update api module version in workflowproj") { sh 'git add .' } |
| helper.createTag("workflowproj/${helper.getGitTag()}") |
| |
| // Update api / workflowproj / container-builder in operator, `make generate-all`, commit, tag and push |
| updateInternalGoModuleWithTag('api', "api/${helper.getGitTag()}") |
| updateInternalGoModuleWithTag('container-builder', "container-builder/${helper.getGitTag()}") |
| updateInternalGoModuleWithTag('workflowproj', "workflowproj/${helper.getGitTag()}") |
| sh 'make generate-all' |
| commitAndPush('origin', "[${helper.getBuildBranch()}] Update internal dependency modules version in go.mod") { sh 'git add .' } |
| } |
| } |
| } |
| } |
| |
| stage('Create Release') { |
| steps { |
| script { |
| dir(helper.getRepoName()) { |
| if(githubscm.isReleaseExist(helper.getGitTag(), helper.getGitAuthorCredsId())) { |
| githubscm.deleteReleaseAndTag(helper.getGitTag(), helper.getGitAuthorPushCredsId()) |
| } |
| githubscm.createReleaseWithGeneratedReleaseNotes(helper.getGitTag(), helper.getBuildBranch(), githubscm.getPreviousTagFromVersion(helper.getProjectVersion(), 'v', '', ['/']), helper.getGitAuthorPushCredsId()) |
| githubscm.updateReleaseBody(helper.getGitTag(), helper.getGitAuthorPushCredsId()) |
| |
| withCredentials([usernamePassword(credentialsId: helper.getGitAuthorPushCredsId(), usernameVariable: 'GH_USER', passwordVariable: 'GH_TOKEN')]) { |
| sh """ |
| gh release upload ${helper.getGitTag()} "operator.yaml" |
| """ |
| } |
| } |
| } |
| } |
| } |
| } |
| post { |
| unsuccessful { |
| sendNotification() |
| } |
| cleanup { |
| script { |
| helper.cleanGoPath() |
| util.cleanNode(containerEngine) |
| } |
| } |
| } |
| } |
| |
| void sendNotification() { |
| if (params.SEND_NOTIFICATION) { |
| mailer.sendMarkdownTestSummaryNotification('Promote', "[${helper.getBuildBranch()}] Kogito Serverless Operator", [env.KOGITO_CI_EMAIL_TO]) |
| } else { |
| echo 'No notification sent per configuration' |
| } |
| } |
| |
| void promoteImage(String oldImageName, String newImageName) { |
| cloud.skopeoCopyRegistryImages(oldImageName, newImageName, Integer.parseInt(env.MAX_REGISTRY_RETRIES)) |
| } |
| |
| void updateInternalGoModuleWithTag(String moduleName, String tagName) { |
| sh """ |
| go get github.com/apache/incubator-kie-kogito-serverless-operator/${moduleName}@${githubscm.getTagCommitHash(tagName)} |
| go mod tidy |
| """ |
| } |
| |
| void commitAndPush(String remote, String commitMsg, Closure preCommit) { |
| if (githubscm.isThereAnyChanges()) { |
| githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId()) |
| githubscm.commitChanges(commitMsg, preCommit) |
| githubscm.pushObject(remote, helper.getBuildBranch(), helper.getGitAuthorPushCredsId()) |
| } else { |
| echo "No change... Skipping commit and push" |
| } |
| } |