From 451095bb5715608f764ca453e5dbf819b3bc2a49 Mon Sep 17 00:00:00 2001 From: radtriste Date: Tue, 17 Oct 2023 10:43:52 +0200 Subject: [PATCH 1/3] Fix pipelines --- .ci/jenkins/Jenkinsfile.build-image | 8 +- .ci/jenkins/Jenkinsfile.deploy | 160 ++++++++++++++------------- .ci/jenkins/Jenkinsfile.setup-branch | 2 +- .ci/jenkins/dsl/jobs.groovy | 2 +- Makefile | 6 +- scripts/README.md | 4 +- scripts/common.py | 2 +- scripts/list-images.py | 2 +- scripts/manage-kogito-version.py | 2 +- scripts/push-local-registry.sh | 2 +- scripts/push-staging.py | 2 +- scripts/retrieve_version.py | 4 +- scripts/update-repository.py | 4 +- tests/test-apps/clone-repo.sh | 2 +- 14 files changed, 102 insertions(+), 100 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile.build-image b/.ci/jenkins/Jenkinsfile.build-image index f13a64043..81889abd6 100644 --- a/.ci/jenkins/Jenkinsfile.build-image +++ b/.ci/jenkins/Jenkinsfile.build-image @@ -67,12 +67,12 @@ pipeline { env.MAVEN_MIRROR_URL = env.MAVEN_MIRROR_REPOSITORY // Ignore self-signed certificates if MAVEN_MIRROR_URL is defined - runPythonCommand("python3 scripts/update-repository.py --build-maven-mirror-url ${MAVEN_MIRROR_URL} --ignore-self-signed-cert") + runPythonCommand("python scripts/update-repository.py --build-maven-mirror-url ${MAVEN_MIRROR_URL} --ignore-self-signed-cert") } if (getMavenArtifactRepository()) { echo "Setup Repository url to '${getMavenArtifactRepository()}'" - runPythonCommand("python3 scripts/update-repository.py --repo-url ${getMavenArtifactRepository()}") + runPythonCommand("python scripts/update-repository.py --repo-url ${getMavenArtifactRepository()}") } } } @@ -89,7 +89,7 @@ pipeline { // echo "[WARN] Artifacts repository defined in env will override the quarkus platform URL in tests. Make sure the platform artifacts are available on that artifacts repository (you can use a maven group)" // } // // Setup quarkus platform repo configuration - // runPythonCommand("python3 scripts/update-repository.py --repo-url ${getQuarkusPlatformURL()} --ignore-self-signed-cert --quarkus-platform-version ${quarkusPlatformVersion}") + // runPythonCommand("python scripts/update-repository.py --repo-url ${getQuarkusPlatformURL()} --ignore-self-signed-cert --quarkus-platform-version ${quarkusPlatformVersion}") // } // } // } @@ -153,7 +153,7 @@ pipeline { } steps { script { - updateTestsCommand = 'python3 scripts/update-repository.py --tests-only' + updateTestsCommand = 'python scripts/update-repository.py --tests-only' updateTestsCommand += getMavenArtifactRepository() ? " --repo-url ${getMavenArtifactRepository()}" : '' updateTestsCommand += getTestsKogitoExamplesRef() ? " --examples-ref ${getTestsKogitoExamplesRef()}" : '' updateTestsCommand += getTestsKogitoExamplesURI() ? " --examples-uri ${getTestsKogitoExamplesURI()}" : '' diff --git a/.ci/jenkins/Jenkinsfile.deploy b/.ci/jenkins/Jenkinsfile.deploy index 83697af7a..00037337e 100644 --- a/.ci/jenkins/Jenkinsfile.deploy +++ b/.ci/jenkins/Jenkinsfile.deploy @@ -14,27 +14,25 @@ pipeline { image env.AGENT_DOCKER_BUILDER_IMAGE args env.AGENT_DOCKER_BUILDER_ARGS } - } + } options { - timeout(time: 120, unit: 'MINUTES') + timeout(time: 240, unit: 'MINUTES') } environment { KOGITO_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}") - - OPENSHIFT_REGISTRY = credentials('OPENSHIFT_REGISTRY') } stages { stage('Initialization') { steps { script { - clean() - currentBuild.displayName = params.DISPLAY_NAME ?: currentBuild.displayName - checkoutRepo() + dir(getRepoName()) { + checkoutRepo() + } if (isRelease()) { // Verify version is set and if on right release branch @@ -62,10 +60,12 @@ pipeline { } steps { script { - if (githubscm.isBranchExist('origin',getPRBranch())) { - githubscm.removeRemoteBranch('origin', getPRBranch()) + dir(getRepoName()) { + if (githubscm.isBranchExist('origin',getPRBranch())) { + githubscm.removeRemoteBranch('origin', getPRBranch()) + } + githubscm.createBranch(getPRBranch()) } - githubscm.createBranch(getPRBranch()) } } } @@ -76,12 +76,14 @@ pipeline { } steps { script { - if (getQuarkusPlatformVersion()) { - runPythonCommand("python3 scripts/update-repository.py --quarkus-platform-version ${getQuarkusPlatformVersion()}") + dir(getRepoName()) { + if (getQuarkusPlatformVersion()) { + sh "python scripts/update-repository.py --quarkus-platform-version ${getQuarkusPlatformVersion()}" - commitAndPushChanges("Update Quarkus Platform version to ${getQuarkusPlatformVersion()}") - } else { - echo 'No new quarkus version given for the release. Statu quo ...' + commitAndPushChanges("Update Quarkus Platform version to ${getQuarkusPlatformVersion()}") + } else { + echo 'No new quarkus version given for the release. Statu quo ...' + } } } } @@ -93,16 +95,18 @@ pipeline { } steps { script { - versionCmd = "python3 scripts/manage-kogito-version.py --bump-to ${getProjectVersion()} --confirm" - if (getBuildBranch() != 'main') { - versionCmd += " --examples-ref ${!isRelease() ? 'nightly-' : ''}${getBuildBranch()}" - } - if (getKogitoArtifactsVersion()) { - versionCmd += " --artifacts-version ${getKogitoArtifactsVersion()}" - } - runPythonCommand(versionCmd) + dir(getRepoName()) { + versionCmd = "python scripts/manage-kogito-version.py --bump-to ${getProjectVersion()} --confirm" + if (getBuildBranch() != 'main') { + versionCmd += " --examples-ref ${!isRelease() ? 'nightly-' : ''}${getBuildBranch()}" + } + if (getKogitoArtifactsVersion()) { + versionCmd += " --artifacts-version ${getKogitoArtifactsVersion()}" + } + sh versionCmd - commitAndPushChanges("Update project version to ${getProjectVersion()}") + commitAndPushChanges("Update project version to ${getProjectVersion()}") + } } } } @@ -110,18 +114,15 @@ pipeline { stage('Validate CeKit Image and Modules descriptors') { steps { script { - sh ''' - curl -Ls https://github.com/kiegroup/kie-cloud-tools/releases/download/v1.3.6/cekit-image-validator-runner.tgz --output cekit-image-validator-runner.tgz - tar -xzvf cekit-image-validator-runner.tgz - chmod +x cekit-image-validator-runner - ''' - sh './cekit-image-validator-runner modules/' - getImages().each { image -> sh "./cekit-image-validator-runner ${image}-image.yaml" } - } - } - post { - always { - sh 'rm -rf cekit-image-validator-runner*' + dir(getRepoName()) { + sh ''' + curl -Ls https://github.com/kiegroup/kie-cloud-tools/releases/download/v1.3.6/cekit-image-validator-runner.tgz --output cekit-image-validator-runner.tgz + tar -xzvf cekit-image-validator-runner.tgz + chmod +x cekit-image-validator-runner + ''' + sh './cekit-image-validator-runner modules/' + getImages().each { image -> sh "./cekit-image-validator-runner ${image}-image.yaml" } + } } } } @@ -129,11 +130,13 @@ pipeline { stage('Build, Push & Test Images') { steps { script { - parallelStages = [:] - getImages().each { image -> - parallelStages["Build&Test ${image}"] = createBuildAndTestStageClosure(image) + dir(getRepoName()) { + parallelStages = [:] + getImages().each { image -> + parallelStages["Build&Test ${image}"] = createBuildAndTestStageClosure(image) + } + parallel parallelStages } - parallel parallelStages } } post { @@ -159,37 +162,39 @@ pipeline { } steps { script { - def commitMsg = "[${getBuildBranch()}] Update Maven artifacts" - def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}." - if (isRelease()) { - commitMsg = "[${getBuildBranch()}] Update project version to ${getProjectVersion()}" - prBody += '\nPlease do not merge, it should be merged automatically.' - } else if (currentBuild.currentResult != 'SUCCESS') { - commitMsg += " (${currentBuild.currentResult})" - prBody += '\n\nSuccessful images:\n' - getBuiltImages().each { - prBody += "- ${it}\n" - } - if (getBuildFailedImages()) { - prBody += '\nBuild failures on those images:\n' - getBuildFailedImages().each { + dir(getRepoName()) { + def commitMsg = "[${getBuildBranch()}] Update Maven artifacts" + def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}." + if (isRelease()) { + commitMsg = "[${getBuildBranch()}] Update project version to ${getProjectVersion()}" + prBody += '\nPlease do not merge, it should be merged automatically.' + } else if (currentBuild.currentResult != 'SUCCESS') { + commitMsg += " (${currentBuild.currentResult})" + prBody += '\n\nSuccessful images:\n' + getBuiltImages().each { prBody += "- ${it}\n" } - } else { - prBody += '\nImages were all successfully built but some other problem occured in the pipeline execution...\n' - } - if (getTestFailedImages()) { - prBody += '\nTest failures on those images:\n' - getTestFailedImages().each { - prBody += "- ${it}\n" + if (getBuildFailedImages()) { + prBody += '\nBuild failures on those images:\n' + getBuildFailedImages().each { + prBody += "- ${it}\n" + } + } else { + prBody += '\nImages were all successfully built but some other problem occured in the pipeline execution...\n' } - } else { - prBody += '\nImages were all successfully built but some other problem occured in the pipeline execution...\n' + if (getTestFailedImages()) { + prBody += '\nTest failures on those images:\n' + getTestFailedImages().each { + prBody += "- ${it}\n" + } + } else { + prBody += '\nImages were all successfully built but some other problem occured in the pipeline execution...\n' + } + prBody += '\nSee build url above for more information' } - prBody += '\nSee build url above for more information' + String prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID()) + deployProperties["${getRepoName()}.pr.link"] = prLink } - String prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID()) - deployProperties["${getRepoName()}.pr.link"] = prLink } } post { @@ -224,9 +229,6 @@ pipeline { unsuccessful { sendUnsuccessfulNotification() } - cleanup { - clean() - } } } @@ -259,10 +261,6 @@ void commitAndPushChanges(String commitMsg) { changesDone = true } -void clean() { - util.cleanNode() -} - void createBuildAndTestStageClosure(String image) { return { stage("Build&Test ${image}") { @@ -348,7 +346,7 @@ String getDeployImageRegistryCredentials() { } String getDeployImageRegistry() { - return isDeployImageInOpenshiftRegistry() ? env.OPENSHIFT_REGISTRY : params.IMAGE_REGISTRY + return isDeployImageInOpenshiftRegistry() ? getOpenShiftRegistry() : params.IMAGE_REGISTRY } String getDeployImageNamespace() { return isDeployImageInOpenshiftRegistry() ? 'openshift' : params.IMAGE_NAMESPACE @@ -404,6 +402,14 @@ String getKogitoArtifactsVersion() { return params.KOGITO_ARTIFACTS_VERSION } +String getOpenShiftRegistry() { + String registry = '' + withCredentials([string(credentialsId: 'OPENSHIFT_REGISTRY', variable: 'OPENSHIFT_REGISTRY')]) { + registry = env.OPENSHIFT_REGISTRY + } + return registry +} + void setDeployPropertyIfNeeded(String key, def value) { if (value) { deployProperties[key] = value @@ -414,11 +420,7 @@ String[] getImages() { if (env.IMAGES_LIST) { return env.IMAGES_LIST.split(',') } - return runPythonCommand("make list | tr '\\n' ','", true).trim().split(',') -} - -void runPythonCommand(String cmd, boolean stdout = false) { - return sh(returnStdout: stdout, script: cmd) + return sh(returnStdout: true, script: "make list | tr '\\n' ','").trim().split(',') } String getQuarkusPlatformVersion() { diff --git a/.ci/jenkins/Jenkinsfile.setup-branch b/.ci/jenkins/Jenkinsfile.setup-branch index 182689cb0..17c2ffb73 100644 --- a/.ci/jenkins/Jenkinsfile.setup-branch +++ b/.ci/jenkins/Jenkinsfile.setup-branch @@ -35,7 +35,7 @@ pipeline { steps { script { dir(getRepoName()) { - versionCmd = "python3 scripts/manage-kogito-version.py --bump-to ${getKogitoVersion()} --confirm" + versionCmd = "python scripts/manage-kogito-version.py --bump-to ${getKogitoVersion()} --confirm" versionCmd += " --examples-ref nightly-${getBuildBranch()}" if (getKogitoArtifactsVersion()) { versionCmd += " --artifacts-version ${getKogitoArtifactsVersion()}" diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index fb18ed05f..8e5331312 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -256,6 +256,6 @@ void setupPromoteJob(JobType jobType) { void setupQuarkusUpdateJob() { KogitoJobUtils.createQuarkusUpdateToolsJob(this, 'kogito-images', [:], [:], [], [ - "source ~/virtenvs/cekit/bin/activate && python3 scripts/update-repository.py --quarkus-platform-version %new_version%" + "python scripts/update-repository.py --quarkus-platform-version %new_version%" ]) } diff --git a/Makefile b/Makefile index 4e2b46570..150a74a67 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -IMAGE_VERSION := $(shell python3 scripts/retrieve_version.py) +IMAGE_VERSION := $(shell python scripts/retrieve_version.py) SHORTENED_LATEST_VERSION := $(shell echo $(IMAGE_VERSION) | awk -F. '{print $$1"."$$2}') KOGITO_APPS_TARGET_BRANCH ?= main KOGITO_APPS_TARGET_URI ?= https://github.com/kiegroup/kogito-apps.git @@ -19,7 +19,7 @@ endif .PHONY: list list: - @python3 scripts/list-images.py $(arg) + @python scripts/list-images.py $(arg) .PHONY: display-image-version display-image-version: @@ -99,7 +99,7 @@ endif .PHONY: push-staging push-staging: build _push-staging _push-staging: - python3 scripts/push-staging.py ${override} + python scripts/push-staging.py ${override} # push to local registry, useful to push the built images to local registry diff --git a/scripts/README.md b/scripts/README.md index b11e68cfb..6b13cceba 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -50,13 +50,13 @@ Utilitary script used to retrieve all images that can be built on this repo, the the community image list: ```bash -$ python3 list-images.py +$ python list-images.py ``` And the product image list by using the `--prod` flag: ```bash -$ python3 list-images.py --prod +$ python list-images.py --prod ``` diff --git a/scripts/common.py b/scripts/common.py index 40b8c7777..f00377ff4 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/python # This script defines some common function that are used by manage-kogito-version.py and push-staging.py script diff --git a/scripts/list-images.py b/scripts/list-images.py index 7cfa9edee..e982d164b 100644 --- a/scripts/list-images.py +++ b/scripts/list-images.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python # Script responsible to update the tests with # Should be run from root directory of the repository diff --git a/scripts/manage-kogito-version.py b/scripts/manage-kogito-version.py index ec344bc81..346215fa4 100644 --- a/scripts/manage-kogito-version.py +++ b/scripts/manage-kogito-version.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python # This script will be responsible to help to manage kogito images and modules version, it will update all needed files # Example of usage: # # move the current version to the next one or rcX diff --git a/scripts/push-local-registry.sh b/scripts/push-local-registry.sh index 157eb11ee..79d2ca899 100644 --- a/scripts/push-local-registry.sh +++ b/scripts/push-local-registry.sh @@ -26,5 +26,5 @@ while read image; do ${BUILD_ENGINE} tag quay.io/kiegroup/${image}:${version} ${registry}/${namespace}/${image}:${version} echo "Deleting imagestream ${image} if exists `oc delete oc -n ${namespace} ${image}`" ${BUILD_ENGINE} push ${registry}/${namespace}/${image}:${version} -done <<<$(python3 scripts/list-images.py) +done <<<$(python scripts/list-images.py) diff --git a/scripts/push-staging.py b/scripts/push-staging.py index 9a95c925f..5fde35932 100644 --- a/scripts/push-staging.py +++ b/scripts/push-staging.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python # This script will be responsible to fetch the latest rc tags from each image and define the next # rc tag to avoid images get overridden. # diff --git a/scripts/retrieve_version.py b/scripts/retrieve_version.py index 64e4274c0..b1b1c7a98 100644 --- a/scripts/retrieve_version.py +++ b/scripts/retrieve_version.py @@ -1,7 +1,7 @@ -#!/usr/bin/python3 +#!/usr/bin/env python #Script responsible to update the tests with #Should be run from root directory of the repository -#Sample usage: python3 scripts/retrieve_version.py +#Sample usage: python scripts/retrieve_version.py import sys sys.dont_write_bytecode = True diff --git a/scripts/update-repository.py b/scripts/update-repository.py index 0c632d1ba..9103b468e 100644 --- a/scripts/update-repository.py +++ b/scripts/update-repository.py @@ -1,7 +1,7 @@ -#!/usr/bin/python3 +#!/usr/bin/env python #Script responsible to update the tests with #Should be run from root directory of the repository -#Sample usage: python3 scripts/update-tests.py +#Sample usage: python scripts/update-tests.py import sys sys.dont_write_bytecode = True diff --git a/tests/test-apps/clone-repo.sh b/tests/test-apps/clone-repo.sh index f39a94bf0..360d1d9fd 100755 --- a/tests/test-apps/clone-repo.sh +++ b/tests/test-apps/clone-repo.sh @@ -8,7 +8,7 @@ if [ -n "${IMAGE_NAME}" ]; then if [[ ${IMAGE_NAME} =~ rhpam|logic* ]]; then prod="--prod" fi - if python3 ../../scripts/list-images.py ${prod} -is ${IMAGE_NAME}; then + if python ../../scripts/list-images.py ${prod} -is ${IMAGE_NAME}; then echo "Target image is supporting services, skipping examples build" exit 0 fi From 9c6f9fcc81167780e8608c38ac290a3686b5eaae Mon Sep 17 00:00:00 2001 From: radtriste Date: Tue, 17 Oct 2023 10:48:36 +0200 Subject: [PATCH 2/3] updated Jenkinsfile --- .ci/jenkins/Jenkinsfile | 46 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile b/.ci/jenkins/Jenkinsfile index 693fa00c2..3bc37e894 100644 --- a/.ci/jenkins/Jenkinsfile +++ b/.ci/jenkins/Jenkinsfile @@ -2,7 +2,10 @@ pipeline { agent { - label 'ubuntu' + docker { + image env.AGENT_DOCKER_BUILDER_IMAGE + args env.AGENT_DOCKER_BUILDER_ARGS + } } options { timeout(time: 120, unit: 'MINUTES') @@ -11,45 +14,44 @@ pipeline { stage('Initialization') { steps { script { - clean() - sh 'printenv' - githubscm.checkoutIfExists(getRepoName(), getChangeAuthor(), getChangeBranch(), 'apache', getChangeTarget(), true) + dir(getRepoName()) { + githubscm.checkoutIfExists(getRepoName(), getChangeAuthor(), getChangeBranch(), 'apache', getChangeTarget(), true) + } } } } stage('Validate CeKit Image and Modules descriptors') { steps { script { - sh ''' - curl -Ls https://github.com/kiegroup/kie-cloud-tools/releases/download/v1.3.6/cekit-image-validator-runner.tgz --output cekit-image-validator-runner.tgz - tar -xzvf cekit-image-validator-runner.tgz - chmod +x cekit-image-validator-runner - ''' - sh './cekit-image-validator-runner modules/' - getImages().each { image -> sh "./cekit-image-validator-runner ${image}-image.yaml" } + dir(getRepoName()) { + sh ''' + curl -Ls https://github.com/kiegroup/kie-cloud-tools/releases/download/v1.3.6/cekit-image-validator-runner.tgz --output cekit-image-validator-runner.tgz + tar -xzvf cekit-image-validator-runner.tgz + chmod +x cekit-image-validator-runner + ''' + sh './cekit-image-validator-runner modules/' + getImages().each { image -> sh "./cekit-image-validator-runner ${image}-image.yaml" } + } } } } stage('Build & Test Images') { steps { script { - parallelStages = [:] - for(String image : getImages()){ - parallelStages[image] = createBuildAndTestStageClosure(image) + dir(getRepoName()) { + parallelStages = [:] + for(String image : getImages()){ + parallelStages[image] = createBuildAndTestStageClosure(image) + } + parallel parallelStages } - parallel parallelStages } } } } post { - always { - script { - clean() - } - } unsuccessful { script { pullrequest.postComment(util.getMarkdownTestSummary('PR', "${BUILD_URL}", 'GITHUB')) @@ -58,10 +60,6 @@ pipeline { } } -void clean() { - util.cleanNode() -} - Closure createBuildAndTestStageClosure(String image) { return { stage("Build&Test ${image}") { From 11822f9ddd0d20a54d9e205fbefa8e2153d39a2d Mon Sep 17 00:00:00 2001 From: radtriste Date: Tue, 17 Oct 2023 11:06:52 +0200 Subject: [PATCH 3/3] update jenkinsfile --- .ci/jenkins/Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile b/.ci/jenkins/Jenkinsfile index 3bc37e894..7a6d29897 100644 --- a/.ci/jenkins/Jenkinsfile +++ b/.ci/jenkins/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { sh 'printenv' dir(getRepoName()) { - githubscm.checkoutIfExists(getRepoName(), getChangeAuthor(), getChangeBranch(), 'apache', getChangeTarget(), true) + githubscm.checkoutIfExists(getRepoName(), getChangeAuthor(), getChangeBranch(), 'apache', getChangeTarget(), true, credentials = [token: getGitAuthorCredentialsId(), usernamePassword: 'kie-ci']) } } } @@ -95,15 +95,15 @@ String[] getImages() { } String getChangeAuthor() { - return env.ghprbAuthorRepoGitUrl ? util.getGroup(env.ghprbAuthorRepoGitUrl) : (env.ghprbPullAuthorLogin ?: CHANGE_AUTHOR) + return CHANGE_AUTHOR } String getChangeBranch() { - return env.ghprbSourceBranch ?: CHANGE_BRANCH + return CHANGE_BRANCH } String getChangeTarget() { - return env.ghprbTargetBranch ?: CHANGE_TARGET + return CHANGE_TARGET } String getRepoName() {