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

kie-issues#755: Fix kogito operator nightly deploy pipelines #1535

Merged
merged 18 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
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
}
29 changes: 14 additions & 15 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ 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 Down Expand Up @@ -55,7 +56,8 @@ pipeline {
}

// Verify we have the connectivity to Openshift
openshift.loginOpenshift()
// TODO: Uncomment this line when we have the Openshift credentials
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need to get them? Or is this in progress in any way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the OpenShift Instance is only used to run the tests. I'm not sure who has the credentials but we need to figure that out to add those credentials to Apache Jenkins.
@porcelli Do you know who can help us with that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have a OpenShift instance available, so better disable this

//openshift.loginOpenshift()
}
}
post {
Expand All @@ -77,7 +79,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 +93,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 @@ -170,14 +172,15 @@ 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())
echo 'Skipping pushing operator image to Openshift registry'
//container.loginOpenshiftRegistry()
//container.tagImage("quay.io/kiegroup/${env.OPERATOR_IMAGE_NAME}:${getOperatorVersion()}",
//helper.buildTempOpenshiftImageFullName())
//container.pushImage(helper.buildTempOpenshiftImageFullName())
}
}
}
Expand All @@ -189,10 +192,6 @@ pipeline {
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 {
Expand Down Expand Up @@ -266,8 +265,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 Down
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
18 changes: 12 additions & 6 deletions .ci/jenkins/scripts/helper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void initPipeline() {
openshift.openshiftApiCredsKey = env.OPENSHIFT_CREDS_KEY

container = load '.ci/jenkins/scripts/container.groovy'
container.containerEngine = env.CONTAINER_ENGINE
container.containerEngine = env.CONTAINER_ENGINE ?: 'docker'
container.containerTlsOptions = env.CONTAINER_ENGINE_TLS_OPTIONS ?: ''
container.containerOpenshift = openshift
}
Expand Down Expand Up @@ -64,14 +64,16 @@ String getTempTag() {
void checkoutRepo(String repoName = '', String directory = '') {
repoName = repoName ?: getRepoName()
closure = {
deleteDir()
checkout(githubscm.resolveRepository(repoName, getGitAuthor(), getBuildBranch(), false))
checkout(githubscm.resolveRepository(repoName, getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsId()))
// need to manually checkout branch since on a detached branch after checkout command
sh "git checkout ${getBuildBranch()}"
}

if (directory) {
dir(directory, closure)
dir(directory) {
deleteDir()
closure()
}
} else {
closure()
}
Expand Down Expand Up @@ -246,8 +248,12 @@ String getGitAuthor() {
return "${GIT_AUTHOR}"
}

String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
String getGitAuthorCredsId() {
return env.GIT_AUTHOR_CREDS_ID
}

String getGitAuthorPushCredsId() {
return env.GIT_AUTHOR_PUSH_CREDS_ID
}

String getPRBranch() {
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ help: ## Display this help.

# Run tests
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
test: fmt lint
test: fmt
./hack/go-test.sh

manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
Expand Down
Loading