From d044e9ead7b720529139c2a9eb6f24c0436440b8 Mon Sep 17 00:00:00 2001 From: radtriste Date: Tue, 17 Oct 2023 11:06:52 +0200 Subject: [PATCH] update jenkinsfile --- .ci/jenkins/Jenkinsfile | 11 +++++---- .ci/jenkins/Jenkinsfile.build-image | 37 ++++++++++++++--------------- .ci/jenkins/Jenkinsfile.deploy | 18 +++++--------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile b/.ci/jenkins/Jenkinsfile index 3bc37e894..f73926cb0 100644 --- a/.ci/jenkins/Jenkinsfile +++ b/.ci/jenkins/Jenkinsfile @@ -17,7 +17,10 @@ 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']) + // TODO Test pupose + deleteDir() + checkout(githubscm.resolveRepository('kogito-images', 'radtriste', 'fix_pipelines', false)) } } } @@ -95,15 +98,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() { diff --git a/.ci/jenkins/Jenkinsfile.build-image b/.ci/jenkins/Jenkinsfile.build-image index 81889abd6..d3bdbcfde 100644 --- a/.ci/jenkins/Jenkinsfile.build-image +++ b/.ci/jenkins/Jenkinsfile.build-image @@ -18,8 +18,6 @@ pipeline { CONTAINER_ENGINE = 'docker' CONTAINER_ENGINE_TLS_OPTIONS = '' - OPENSHIFT_API = credentials('OPENSHIFT_API') - OPENSHIFT_REGISTRY = credentials('OPENSHIFT_REGISTRY') OPENSHIFT_CREDS_KEY = 'OPENSHIFT_CREDS' IMAGE_BUILD_PLATFORMS = 'linux/amd64,linux/arm64' @@ -28,8 +26,6 @@ pipeline { stage('Initialization') { steps { script { - clean() - sh 'printenv' assert getBuildImageName() : 'Please provide `BUILD_IMAGE_NAME` parameter' @@ -49,7 +45,7 @@ pipeline { // Login to final registry if deploy is needed if (shouldDeployImage()) { if (isDeployImageInOpenshiftRegistry()) { - cloud.loginOpenShift(env.OPENSHIFT_API, env.OPENSHIFT_CREDS_KEY) + cloud.loginOpenShift(getOpenShiftAPI(), env.OPENSHIFT_CREDS_KEY) cloud.loginOpenshiftRegistry(env.CONTAINER_ENGINE, env.CONTAINER_ENGINE_TLS_OPTIONS ?: '') } else if (getDeployImageRegistryCredentials()) { cloud.loginContainerRegistry(getDeployImageRegistry(), getDeployImageRegistryCredentials(), env.CONTAINER_ENGINE, env.CONTAINER_ENGINE_TLS_OPTIONS ?: '') @@ -199,24 +195,11 @@ pipeline { always { script { updateGithubCommitStatusFromBuildResult() - - clean() } } } } -void clean() { - util.cleanNode(env.CONTAINER_ENGINE) - - cloud.cleanDockerMultiplatformBuild() - cloud.cleanLocalRegistry() - cloud.cleanSkopeo() - - // Clean Cekit cache, in case we reuse an old node - sh "rm -rf \$HOME/.cekit/cache" -} - String getMakeBuildImageArgs() { List args = [] if (getBuildKogitoAppsRef()) { @@ -261,7 +244,7 @@ String getDeployImageRegistryCredentials() { } String getDeployImageRegistry() { - return isDeployImageInOpenshiftRegistry() ? env.OPENSHIFT_REGISTRY : params.DEPLOY_IMAGE_REGISTRY + return isDeployImageInOpenshiftRegistry() ? getOpenShiftRegistry() : params.DEPLOY_IMAGE_REGISTRY } String getDeployImageNamespace() { @@ -292,6 +275,22 @@ boolean isDeployLatestTag() { // utils //////////////////////////////////////////////////////////////////////// +String getOpenShiftRegistry() { + String registry = '' + withCredentials([string(credentialsId: 'OPENSHIFT_REGISTRY', variable: 'OPENSHIFT_REGISTRY')]) { + registry = env.OPENSHIFT_REGISTRY + } + return registry +} + +String getOpenShiftAPI() { + String openShiftAPI = '' + withCredentials([string(credentialsId: 'OPENSHIFT_API', variable: 'OPENSHIFT_API')]) { + openShiftAPI = env.OPENSHIFT_API + } + return openShiftAPI +} + String getRepoName() { return env.REPO_NAME } diff --git a/.ci/jenkins/Jenkinsfile.deploy b/.ci/jenkins/Jenkinsfile.deploy index 00037337e..4441c2731 100644 --- a/.ci/jenkins/Jenkinsfile.deploy +++ b/.ci/jenkins/Jenkinsfile.deploy @@ -4,9 +4,9 @@ deployProperties = [:] changesDone = false -BUILT_IMAGES = [] -BUILD_FAILED_IMAGES = [] -TEST_FAILED_IMAGES = [] +BUILT_IMAGES = Collections.synchronizedList([]) +BUILD_FAILED_IMAGES = Collections.synchronizedList([]) +TEST_FAILED_IMAGES = Collections.synchronizedList([]) pipeline { agent { @@ -304,21 +304,15 @@ void createBuildAndTestStageClosure(String image) { } void registerBuiltImage(String imageName) { - lock("${BUILD_URL} build success") { - BUILT_IMAGES.add(imageName) - } + BUILT_IMAGES.add(imageName) } void registerBuildFailedImage(String imageName) { - lock("${BUILD_URL} build failed") { - BUILD_FAILED_IMAGES.add(imageName) - } + BUILD_FAILED_IMAGES.add(imageName) } void registerTestFailedImage(String imageName) { - lock("${BUILD_URL} test failed") { - TEST_FAILED_IMAGES.add(imageName) - } + TEST_FAILED_IMAGES.add(imageName) } List getBuiltImages() {