| @Library('jenkins-pipeline-shared-libraries')_ |
| |
| IMAGES = ['kogito-serverless-operator'] |
| |
| helper = null |
| |
| pipeline { |
| agent { |
| label 'kie-rhel8 && podman && !built-in' |
| } |
| |
| options { |
| timeout(time: 120, unit: 'MINUTES') |
| timestamps() |
| } |
| |
| tools { |
| go 'golang-1.19' |
| } |
| |
| environment { |
| KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") |
| |
| // Linked to node label |
| CONTAINER_ENGINE = 'podman' |
| CONTAINER_ENGINE_TLS_OPTIONS = '--tls-verify=false' |
| |
| PR_BRANCH_HASH = "${util.generateHash(10)}" |
| GITHUB_REPO = "${REPO_NAME}" // for github-release cli |
| } |
| |
| 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) |
| |
| cloud.installSkopeo() |
| } |
| } |
| } |
| 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.getGitAuthorCredsID()) |
| githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorCredsID()) |
| } |
| |
| // 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.getGitAuthorCredsID()) |
| } |
| githubscm.createReleaseWithGeneratedReleaseNotes(helper.getGitTag(), helper.getBuildBranch(), githubscm.getPreviousTagFromVersion(helper.getProjectVersion(), 'v', '', ['/']), helper.getGitAuthorCredsID()) |
| githubscm.updateReleaseBody(helper.getGitTag(), helper.getGitAuthorCredsID()) |
| |
| withCredentials([usernamePassword(credentialsId: helper.getGitAuthorCredsID(), usernameVariable: 'GH_USER', passwordVariable: 'GH_TOKEN')]) { |
| sh """ |
| gh release upload ${helper.getGitTag()} "operator.yaml" |
| """ |
| } |
| } |
| } |
| } |
| } |
| } |
| post { |
| unsuccessful { |
| sendNotification() |
| } |
| cleanup { |
| script { |
| helper.cleanGoPath() |
| util.cleanNode(containerEngine) |
| cloud.cleanSkopeo() |
| } |
| } |
| } |
| } |
| |
| 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/kiegroup/kogito-serverless-operator/${moduleName}@${githubscm.getTagCommitHash(tagName)} |
| go mod tidy |
| """ |
| } |
| |
| void commitAndPush(String remote, String commitMsg, Closure preCommit) { |
| if (githubscm.isThereAnyChanges()) { |
| githubscm.commitChanges(commitMsg, preCommit) |
| githubscm.pushObject(remote, helper.getBuildBranch(), helper.getGitAuthorCredsID()) |
| } else { |
| echo "No change... Skipping commit and push" |
| } |
| } |