Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
kie-issues#755: Fix kogito operator nightly deploy pipelines (#1535)
Browse files Browse the repository at this point in the history
* kie-issues#755: initial adjustment for ASF jenkins

* Add workaround for Lock plugin, remove directory deletion before git checkout and add default container engine

* Comment out login to OpenShift call

* Force bash shell usage on sh steps

* Force bash shell usage on sh steps

* Revert last commit

* set user config for git

* Add TODO

* Disable fmt on tests

* Setup minikube

* Setup minikube

* Setup minikube

* Remove OpenShift related code

* Remove OpenShift related code

* Move ansible installation to the kogito-ci-build image

* Remove minikube step

* Add CONTAINER_ENGINE env var

* Fix push images to quay.io

---------

Co-authored-by: jstastny-cz <[email protected]>
  • Loading branch information
rodrigonull and jstastny-cz authored Jan 12, 2024
1 parent db398c8 commit 34a5aa1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 142 deletions.
22 changes: 15 additions & 7 deletions .ci/jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ testsFailed = false

pipeline {
agent {
label 'kogito-jenkins-node && !master' // Running on IBMCLoud jenkins, no change to be done there
}
tools {
go 'golang-1.17'
docker {
image env.AGENT_DOCKER_BUILDER_IMAGE
args env.AGENT_DOCKER_BUILDER_ARGS
}
}
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')
Expand All @@ -30,9 +30,9 @@ pipeline {
script {
cleanGoPath()

sh ' git config --global user.email "jenkins@kie.com" '
sh ' git config --global user.name "kie user"'
githubscm.checkoutIfExists('incubator-kie-kogito-operator', changeAuthor, changeBranch, 'apache', changeTarget, true, ['token' : 'GITHUB_TOKEN', 'usernamePassword' : 'user-kie-ci10'])
sh ' git config --global user.email "jenkins@kie.apache.org" '
sh ' git config --global user.name "Apache KIE user"'
githubscm.checkoutIfExists('incubator-kie-kogito-operator', changeAuthor, changeBranch, 'apache', changeTarget, true, credentials = [token: getGitAuthorTokenCredentialsId(), usernamePassword: getGitAuthorCredentialsId()])
sh "set +x && oc login --token=\$(oc whoami -t) --server=${OPENSHIFT_API} --insecure-skip-tls-verify"
}
}
Expand Down Expand Up @@ -158,3 +158,11 @@ String getBDDParameters() {
echo "BDD parameters = ${testParams}"
return testParams
}

String getGitAuthorCredentialsId() {
return env.GIT_AUTHOR_CREDS_ID
}

String getGitAuthorTokenCredentialsId() {
return env.GIT_AUTHOR_TOKEN_CREDS_ID
}
132 changes: 18 additions & 114 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
@Library('jenkins-pipeline-shared-libraries')_

helper = null
testsFailed = false

gitChanges = false

pipeline {
agent {
docker {
docker {
image env.AGENT_DOCKER_BUILDER_IMAGE
args env.AGENT_DOCKER_BUILDER_ARGS
}
}

options {
timeout(time: 24, unit: 'HOURS') // Give the day to be executed (due to the lock)
disableConcurrentBuilds() // Workaround for missing lock plugin installed on ASF Jenkins
}

environment {
Expand All @@ -26,6 +25,8 @@ pipeline {
OP_TEST_CONTAINER_OPT = '-t'
OP_TEST_DEBUG = 1
OP_TEST_CONTAINER_TOOL = 'docker'

CONTAINER_ENGINE = 'docker'
}

stages {
Expand Down Expand Up @@ -53,9 +54,6 @@ pipeline {
assert helper.getBuildBranch() == util.getReleaseBranchFromVersion(helper.getProjectVersion())
}
}

// Verify we have the connectivity to Openshift
openshift.loginOpenshift()
}
}
post {
Expand All @@ -77,7 +75,7 @@ pipeline {
steps {
script {
if (githubscm.isBranchExist('origin', helper.getPRBranch())) {
githubscm.removeRemoteBranch('origin', helper.getPRBranch())
githubscm.removeRemoteBranch('origin', helper.getPRBranch(), helper.getGitAuthorPushCredsId())
}
githubscm.createBranch(helper.getPRBranch())
}
Expand All @@ -91,7 +89,7 @@ pipeline {
steps {
script {
sh "make bump-version new_version=${helper.getProjectVersion()}"

githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges("Update project version to ${helper.getProjectVersion()}", {
sh '''
git add .
Expand Down Expand Up @@ -125,7 +123,7 @@ pipeline {

stage('Build Kogito Operator') {
steps {
sh "source ~/virtenvs/cekit/bin/activate && make BUILDER=${env.CONTAINER_ENGINE}"
sh "make BUILDER=${env.CONTAINER_ENGINE}"
}
post {
unsuccessful {
Expand Down Expand Up @@ -153,6 +151,7 @@ pipeline {
}
}
}

stage('Run OLM tests') {
when {
expression {
Expand All @@ -170,58 +169,6 @@ pipeline {
}
}
}
stage('Push Operator Image to Openshift Registry') {
steps {
script {
container.loginOpenshiftRegistry()

container.tagImage("quay.io/kiegroup/${env.OPERATOR_IMAGE_NAME}:${getOperatorVersion()}",
helper.buildTempOpenshiftImageFullName())
container.pushImage(helper.buildTempOpenshiftImageFullName())
}
}
}

stage('Run BDD tests') {
when {
beforeOptions true
expression {
return helper.shouldLaunchTests()
}
}
options {
// Lock on OCP API as we want only one run at a time
lock("BDD tests on OCP API ${getLockOpenshiftApi()}")
}
stages {
stage('Run full testing') {
options {
timeout(time: 360, unit: 'MINUTES')
}
steps {
script {
// Catch and set unstable so the temp image is still pushed and we get the deployment properties,
// in case we decide to continue in the release
try {
sh "make run-tests timeout=360 load_factor=2 concurrent=2 smoke=${params.SMOKE_TESTS_ONLY} ${getBDDParameters()}"
} catch (err) {
testsFailed = true
util.archiveConsoleLog()
}
}
}
post {
always {
archiveArtifacts artifacts: 'test/logs/**/*.log', allowEmptyArchive: false
junit testResults: 'test/logs/**/junit.xml', allowEmptyResults: false
}
cleanup {
sh 'cd test && go run scripts/prune_namespaces.go'
}
}
}
}
}

stage('Push to registry') {
when {
Expand All @@ -231,19 +178,19 @@ pipeline {
script {
helper.loginRegistry()

container.tagImage(helper.buildTempOpenshiftImageFullName(), helper.getImageFullTag(env.OPERATOR_IMAGE_NAME))
container.pushImage(helper.getImageFullTag(env.OPERATOR_IMAGE_NAME))
image = "quay.io/kiegroup/${env.OPERATOR_IMAGE_NAME}:${getOperatorVersion()}"
container.pushImage(image)

if (helper.isDeployLatestTag()) {
String finalFullImage = helper.getImageFullTag(env.OPERATOR_IMAGE_NAME, defaultImageParamsPrefix, 'latest')
container.tagImage(helper.buildTempOpenshiftImageFullName(), finalFullImage)
container.tagImage(image, finalFullImage)
container.pushImage(finalFullImage)
}

String reducedTag = helper.getReducedTag()
if (reducedTag) {
String finalFullImage = helper.getImageFullTag(env.OPERATOR_IMAGE_NAME, defaultImageParamsPrefix, reducedTag)
container.tagImage(helper.buildTempOpenshiftImageFullName(), finalFullImage)
container.tagImage(image, finalFullImage)
container.pushImage(finalFullImage)
}

Expand All @@ -266,8 +213,8 @@ pipeline {
if (gitChanges) {
String prMsg = "[${helper.getBuildBranch()}] Update version to ${helper.getProjectVersion()}"
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it shoud be merged automatically."
githubscm.pushObject('origin', helper.getPRBranch(), helper.getGitAuthorCredsID())
prLink = githubscm.createPR(prMsg, prBody, helper.getBuildBranch(), helper.getGitAuthorCredsID())
githubscm.pushObject('origin', helper.getPRBranch(), helper.getGitAuthorPushCredsId())
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.getGitAuthor()}/${helper.getRepoName()}")
Expand All @@ -286,11 +233,6 @@ pipeline {
script {
properties.writeToFile(env.PROPERTIES_FILE_NAME)
archiveArtifacts(artifacts: env.PROPERTIES_FILE_NAME)

// Verify here if BDD tests due to test errors or build error
if (testsFailed && currentBuild.currentResult == 'SUCCESS') {
error 'There was a test execution failure'
}
}
}
unsuccessful {
Expand All @@ -305,52 +247,14 @@ pipeline {
}
}

String getOperatorVersion() {
return sh(script: 'source ./hack/env.sh > /dev/null && echo $(getOperatorVersion)', returnStdout: true).trim()
}

void sendNotification() {
if (params.SEND_NOTIFICATION) {
mailer.sendMarkdownTestSummaryNotification('Deploy', "[${helper.getBuildBranch()}] Kogito Operator", [env.KOGITO_CI_EMAIL_TO], "You can find test error logs here: ${BUILD_URL}/artifact/test/logs/error/")
} else {
echo 'No notification sent per configuration'
}
}

String getOperatorVersion() {
return sh(script: 'source ./hack/env.sh > /dev/null && echo $(getOperatorVersion)', returnStdout: true).trim()
}

// Special method to get the Openshift API in the lock because env is not accessible yet
void getLockOpenshiftApi() {
withCredentials([string(credentialsId: 'OPENSHIFT_API', variable: 'OPENSHIFT_API')]) {
return env.OPENSHIFT_API
}
}

////////////////////////////////////////////////////////////////////////
// BDD parameters

String getBDDParameters() {
Map testParamsMap = helper.getBDDCommonParameters(true)

testParamsMap.putAll(helper.getBDDBuildImageParameters('KOGITO_IMAGES'))
testParamsMap.putAll(helper.getBDDServicesImageParameters('KOGITO_IMAGES'))

testParamsMap['image_cache_mode'] = params.EXAMPLES_IMAGES_CACHE_MODE
testParamsMap.putAll(helper.getBDDRuntimeImageParameters('EXAMPLES_IMAGES'))

// Add tags
def tags = []
if (params.BDD_TEST_TAGS) {
tags.add(params.BDD_TEST_TAGS)
}
if (params.SKIP_NATIVE_TESTS) {
tags.add("~${helper.getNativeTag()}")
}
if (params.SKIP_NON_NATIVE_TESTS) {
tags.add("~${helper.getNonNativeTag()}")
}
testParamsMap['tags'] = tags.join('&&')

String testParams = testParamsMap.findAll { entry -> entry.getValue() }
.collect { entry -> "${entry.getKey()}=\"${entry.getValue()}\"" }.join(' ')
echo "BDD parameters = ${testParams}"
return testParams
}
14 changes: 7 additions & 7 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ pipeline {
// Merge PR
String prLink = properties.retrieve("${helper.getRepoName()}.pr.link")
if (prLink) {
githubscm.mergePR(prLink, helper.getGitAuthorCredsID())
githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorCredsID())
githubscm.mergePR(prLink, helper.getGitAuthorPushCredsId())
githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorPushCredsId())
}
}
}
Expand All @@ -108,11 +108,11 @@ pipeline {
steps {
script {
dir(helper.getRepoName()) {
if (githubscm.isReleaseExist(helper.getGitTag(), helper.getGitAuthorCredsID())) {
githubscm.deleteReleaseAndTag(helper.getGitTag(), helper.getGitAuthorCredsID())
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.getGitAuthorCredsID())
githubscm.updateReleaseBody(helper.getGitTag(), helper.getGitAuthorCredsID())
githubscm.createReleaseWithGeneratedReleaseNotes(helper.getGitTag(), helper.getBuildBranch(), githubscm.getPreviousTagFromVersion(helper.getProjectVersion(), 'v'), helper.getGitAuthorPushCredsId())
githubscm.updateReleaseBody(helper.getGitTag(), helper.getGitAuthorPushCredsId())

sh "make build-cli release=true version=${helper.getProjectVersion()}"
def releasePath = 'build/_output/release/'
Expand All @@ -121,7 +121,7 @@ pipeline {
def linuxFileName = "${cliBaseName}-linux-amd64.tar.gz"
def windowsFileName = "${cliBaseName}-windows-amd64.zip"
def yamlInstaller = 'kogito-operator.yaml'
withCredentials([usernamePassword(credentialsId: helper.getGitAuthorCredsID(), usernameVariable: 'GH_USER', passwordVariable: 'GH_TOKEN')]) {
withCredentials([usernamePassword(credentialsId: helper.getGitAuthorPushCredsId(), usernameVariable: 'GH_USER', passwordVariable: 'GH_TOKEN')]) {
sh """
gh release upload ${helper.getGitTag()} "${releasePath}${darwinFileName}"
gh release upload ${helper.getGitTag()} "${releasePath}${linuxFileName}"
Expand Down
3 changes: 2 additions & 1 deletion .ci/jenkins/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ pipeline {
git checkout -- go.sum
'''
if (githubscm.isThereAnyChanges()) {
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges("[${helper.getBuildBranch()}] Update version to ${helper.getProjectVersion()}", {
sh '''
git add .
'''
})
githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorCredsID())
githubscm.pushObject('origin', helper.getBuildBranch(), helper.getGitAuthorPushCredsId())
} else {
println '[WARN] no changes to commit'
}
Expand Down
14 changes: 8 additions & 6 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ void createSetupBranchJob() {
jobParams.env.putAll([
JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",
GIT_AUTHOR: "${GIT_AUTHOR_NAME}",
AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",

IS_MAIN_BRANCH: "${Utils.isMainBranch(this)}"
])
Expand Down Expand Up @@ -114,8 +114,8 @@ void setupDeployJob(JobType jobType) {

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",

AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",

DEFAULT_STAGING_REPOSITORY: "${MAVEN_NEXUS_STAGING_PROFILE_URL}",
MAVEN_ARTIFACT_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
Expand Down Expand Up @@ -189,8 +189,8 @@ void setupPromoteJob(JobType jobType) {

GIT_AUTHOR: "${GIT_AUTHOR_NAME}",

AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GIT_AUTHOR_PUSH_CREDS_ID: "${GIT_AUTHOR_PUSH_CREDENTIALS_ID}",
])
KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
parameters {
Expand Down Expand Up @@ -252,6 +252,8 @@ void setupExamplesImagesDeployJob(JobType jobType, String jobName = 'kogito-exam
jobParams.env.putAll([
GIT_AUTHOR: "${GIT_AUTHOR_NAME}",

GIT_AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",

DEFAULT_STAGING_REPOSITORY: "${MAVEN_NEXUS_STAGING_PROFILE_URL}",
MAVEN_ARTIFACT_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
])
Expand Down
Loading

0 comments on commit 34a5aa1

Please sign in to comment.