From 6099de8cf72029dfdbdc3f4303d9656736bd165d Mon Sep 17 00:00:00 2001 From: radtriste Date: Wed, 13 Sep 2023 14:23:44 +0200 Subject: [PATCH 1/2] Create multibranch kogito-ci-build image job --- ...mage => Jenkinsfile.build-kogito-ci-image} | 10 ++-- .ci/jenkins/config/branch.yaml | 4 +- .ci/jenkins/dsl/jobs.groovy | 28 ++++++----- .../jenkins/jobdsl/KogitoJobTemplate.groovy | 48 ++++++++++++++++++- 4 files changed, 69 insertions(+), 21 deletions(-) rename .ci/jenkins/{Jenkinsfile.tools.build-kogito-ci-image => Jenkinsfile.build-kogito-ci-image} (91%) diff --git a/.ci/jenkins/Jenkinsfile.tools.build-kogito-ci-image b/.ci/jenkins/Jenkinsfile.build-kogito-ci-image similarity index 91% rename from .ci/jenkins/Jenkinsfile.tools.build-kogito-ci-image rename to .ci/jenkins/Jenkinsfile.build-kogito-ci-image index bd64b18d4..fba0135fd 100644 --- a/.ci/jenkins/Jenkinsfile.tools.build-kogito-ci-image +++ b/.ci/jenkins/Jenkinsfile.build-kogito-ci-image @@ -13,8 +13,6 @@ pipeline { IMAGE_NAME = 'quay.io/kiegroup/kogito-ci-build' IMAGE_TAG = "${BRANCH_NAME}-build-${BUILD_NUMBER}" IMAGE_NAME_TAG = "${env.IMAGE_NAME}:${env.IMAGE_TAG}" - COMMIT_IMAGE_NAME_TAG = "${env.IMAGE_NAME}:${GIT_COMMIT}" - LATEST_IMAGE_NAME_TAG = "${env.IMAGE_NAME}:${BRANCH_NAME}-latest" } options { @@ -38,14 +36,14 @@ pipeline { sh """ docker build --build-arg SDKMAN_JAVA=11.0.20-tem -t ${env.IMAGE_NAME_TAG} -f apache-nodes/Dockerfile.kogito-ci-build . - docker tag ${env.IMAGE_NAME_TAG} ${env.COMMIT_IMAGE_NAME_TAG} - docker tag ${env.IMAGE_NAME_TAG} ${env.LATEST_IMAGE_NAME_TAG} + docker tag ${env.IMAGE_NAME_TAG} ${env.IMAGE_NAME}:${GIT_COMMIT} + docker tag ${env.IMAGE_NAME_TAG} ${env.IMAGE_NAME}:${BRANCH_NAME}-latest """ sh """ docker --config ${DOCKER_CONFIG} push ${env.IMAGE_NAME_TAG} - docker --config ${DOCKER_CONFIG} push ${env.COMMIT_IMAGE_NAME_TAG} - docker --config ${DOCKER_CONFIG} push ${env.LATEST_IMAGE_NAME_TAG} + docker --config ${DOCKER_CONFIG} push ${env.IMAGE_NAME}:${GIT_COMMIT} + docker --config ${DOCKER_CONFIG} push ${env.IMAGE_NAME}:${BRANCH_NAME}-latest """ } } diff --git a/.ci/jenkins/config/branch.yaml b/.ci/jenkins/config/branch.yaml index d2d2c066b..5f2805708 100644 --- a/.ci/jenkins/config/branch.yaml +++ b/.ci/jenkins/config/branch.yaml @@ -95,7 +95,9 @@ jenkins: agent: docker: builder: - image: quay.io/kiegroup/kogito-ci-build:latest + # At some point, this image will need to be changed when a release branch is created + # but we need to make sure the image exists first ... simple tag before setting up the branch ? + image: quay.io/kiegroup/kogito-ci-build:main-latest args: -v /var/run/docker.sock:/var/run/docker.sock --group-add docker --group-add input --group-add render default_tools: jdk: jdk_11_latest diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy index 0835db134..63755c3af 100644 --- a/.ci/jenkins/dsl/jobs.groovy +++ b/.ci/jenkins/dsl/jobs.groovy @@ -5,7 +5,7 @@ import org.kie.jenkins.jobdsl.utils.VersionUtils import org.kie.jenkins.jobdsl.KogitoJobUtils import org.kie.jenkins.jobdsl.Utils -JENKINSFILE_PATH = '.ci/jenkins' +jenkins_path = '.ci/jenkins' boolean isMainStream() { return Utils.getStream(this) == 'main' @@ -57,25 +57,27 @@ KogitoJobUtils.createEnvironmentIntegrationBranchNightlyJob(this, 'quarkus-3', [ setupReleaseArtifactsJob() setupReleaseCloudJob() +Utils.isMainBranch(this) && KogitoJobTemplate.createBranchMultibranchPipelineJob(this, 'kogito-ci-build-image', "${jenkins_path}/Jenkinsfile.build-kogito-ci-image") + ///////////////////////////////////////////////////////////////// // Methods ///////////////////////////////////////////////////////////////// void setupCleanOldNamespacesToolsJob() { - def jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-clean-old-namespaces', JobType.TOOLS, "${JENKINSFILE_PATH}/Jenkinsfile.tools.clean-old-namespaces") + def jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-clean-old-namespaces', JobType.TOOLS, "${jenkins_path}/Jenkinsfile.tools.clean-old-namespaces") jobParams.triggers = [ cron : '@midnight' ] KogitoJobTemplate.createPipelineJob(this, jobParams) } void setupCleanOldNightlyImagesToolsJob() { - jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-clean-old-nightly-images', JobType.TOOLS, "${JENKINSFILE_PATH}/Jenkinsfile.tools.clean-nightly-images") + jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-clean-old-nightly-images', JobType.TOOLS, "${jenkins_path}/Jenkinsfile.tools.clean-nightly-images") jobParams.triggers = [ cron : 'H 8 * * *' ] JobParamsUtils.setupJobParamsAgentDockerBuilderImageConfiguration(this, jobParams) KogitoJobTemplate.createPipelineJob(this, jobParams) } void setupCreateIssueToolsJob() { - jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-create-issue', JobType.TOOLS, "${JENKINSFILE_PATH}/Jenkinsfile.tools.create-issue") + jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-create-issue', JobType.TOOLS, "${jenkins_path}/Jenkinsfile.tools.create-issue") jobParams.env.putAll([ GITHUB_CLI_PATH: '/opt/tools/gh-cli/bin/gh', ]) @@ -92,7 +94,7 @@ void setupCreateIssueToolsJob() { } void setupUpdateJenkinsDependenciesJob() { - jobParams = JobParamsUtils.getBasicJobParams(this, 'jenkins-update-framework-deps', JobType.TOOLS, "${JENKINSFILE_PATH}/Jenkinsfile.tools.update-jenkins-dependencies", 'Nightly check of Jenkins dependencies from framework against current version of Jenkins') + jobParams = JobParamsUtils.getBasicJobParams(this, 'jenkins-update-framework-deps', JobType.TOOLS, "${jenkins_path}/Jenkinsfile.tools.update-jenkins-dependencies", 'Nightly check of Jenkins dependencies from framework against current version of Jenkins') jobParams.triggers = [cron : '@midnight'] jobParams.env.putAll([ REPO_NAME: 'kogito-pipelines', @@ -106,7 +108,7 @@ void setupUpdateJenkinsDependenciesJob() { } void createSetupBranchJob() { - def jobParams = JobParamsUtils.getBasicJobParams(this, '0-setup-branch', JobType.SETUP_BRANCH, "${JENKINSFILE_PATH}/Jenkinsfile.setup-branch", 'Kogito Setup Branch for Artifacts') + def jobParams = JobParamsUtils.getBasicJobParams(this, '0-setup-branch', JobType.SETUP_BRANCH, "${jenkins_path}/Jenkinsfile.setup-branch", 'Kogito Setup Branch for Artifacts') jobParams.env.putAll([ JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}", @@ -125,7 +127,7 @@ void createSetupBranchJob() { } void createSetupBranchCloudJob() { - def jobParams = JobParamsUtils.getBasicJobParams(this, '0-setup-branch-cloud', JobType.SETUP_BRANCH, "${JENKINSFILE_PATH}/Jenkinsfile.setup-branch.cloud", 'Kogito Setup Branch for Cloud') + def jobParams = JobParamsUtils.getBasicJobParams(this, '0-setup-branch-cloud', JobType.SETUP_BRANCH, "${jenkins_path}/Jenkinsfile.setup-branch.cloud", 'Kogito Setup Branch for Cloud') jobParams.env.putAll([ JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}", @@ -142,7 +144,7 @@ void createSetupBranchCloudJob() { } void setupNightlyJob() { - def jobParams = JobParamsUtils.getBasicJobParams(this, '0-kogito-nightly', JobType.NIGHTLY, "${JENKINSFILE_PATH}/Jenkinsfile.nightly", 'Kogito Nightly') + def jobParams = JobParamsUtils.getBasicJobParams(this, '0-kogito-nightly', JobType.NIGHTLY, "${jenkins_path}/Jenkinsfile.nightly", 'Kogito Nightly') jobParams.triggers = [cron : isMainStream () ? '@midnight' : 'H 4 * * *'] jobParams.env.putAll([ JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}", @@ -160,7 +162,7 @@ void setupNightlyJob() { } void setupNightlyCloudJob() { - def jobParams = JobParamsUtils.getBasicJobParams(this, '0-kogito-nightly-cloud', JobType.NIGHTLY, "${JENKINSFILE_PATH}/Jenkinsfile.nightly.cloud", 'Kogito Nightly') + def jobParams = JobParamsUtils.getBasicJobParams(this, '0-kogito-nightly-cloud', JobType.NIGHTLY, "${jenkins_path}/Jenkinsfile.nightly.cloud", 'Kogito Nightly') jobParams.env.putAll([ JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}", @@ -226,7 +228,7 @@ void setupQuarkus3NightlyJob() { } void setupQuarkusPlatformJob(JobType jobType) { - def jobParams = JobParamsUtils.getBasicJobParams(this, 'quarkus-platform.deploy', jobType, "${JENKINSFILE_PATH}/Jenkinsfile.nightly.quarkus-platform", 'Kogito Quarkus platform job') + def jobParams = JobParamsUtils.getBasicJobParams(this, 'quarkus-platform.deploy', jobType, "${jenkins_path}/Jenkinsfile.nightly.quarkus-platform", 'Kogito Quarkus platform job') JobParamsUtils.setupJobParamsAgentDockerBuilderImageConfiguration(this, jobParams) jobParams.env.putAll([ JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}", @@ -241,7 +243,7 @@ void setupQuarkusPlatformJob(JobType jobType) { } void setupReleaseArtifactsJob() { - def jobParams = JobParamsUtils.getBasicJobParams(this, '0-kogito-release', JobType.RELEASE, "${JENKINSFILE_PATH}/Jenkinsfile.release", 'Kogito Artifacts Release') + def jobParams = JobParamsUtils.getBasicJobParams(this, '0-kogito-release', JobType.RELEASE, "${jenkins_path}/Jenkinsfile.release", 'Kogito Artifacts Release') jobParams.env.putAll([ JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}", @@ -267,7 +269,7 @@ void setupReleaseArtifactsJob() { } void setupReleaseCloudJob() { - def jobParams = JobParamsUtils.getBasicJobParams(this, '0-kogito-release-cloud', JobType.RELEASE, "${JENKINSFILE_PATH}/Jenkinsfile.release.cloud", 'Kogito Cloud Release') + def jobParams = JobParamsUtils.getBasicJobParams(this, '0-kogito-release-cloud', JobType.RELEASE, "${jenkins_path}/Jenkinsfile.release.cloud", 'Kogito Cloud Release') jobParams.env.putAll([ JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}", @@ -308,7 +310,7 @@ void setupReleaseCloudJob() { } void setupBuildOperatorNode() { - def jobParams = JobParamsUtils.getBasicJobParams(this, 'build-operator-node', JobType.TOOLS, "${JENKINSFILE_PATH}/Jenkinsfile.build-operator-node") + def jobParams = JobParamsUtils.getBasicJobParams(this, 'build-operator-node', JobType.TOOLS, "${jenkins_path}/Jenkinsfile.build-operator-node") KogitoJobTemplate.createPipelineJob(this, jobParams) } diff --git a/dsl/seed/src/main/groovy/org/kie/jenkins/jobdsl/KogitoJobTemplate.groovy b/dsl/seed/src/main/groovy/org/kie/jenkins/jobdsl/KogitoJobTemplate.groovy index 9e8751df4..779731f3e 100644 --- a/dsl/seed/src/main/groovy/org/kie/jenkins/jobdsl/KogitoJobTemplate.groovy +++ b/dsl/seed/src/main/groovy/org/kie/jenkins/jobdsl/KogitoJobTemplate.groovy @@ -467,7 +467,8 @@ class KogitoJobTemplate { } static def createPullRequestMultibranchPipelineJob(def script, String jenkinsFilePath = '.ci/jenkins/Jenkinsfile') { - PrintUtils.debug(script, "Create pull request job ${Utils.getJobDisplayName(script)}-pr") + String jobName = "${Utils.getJobDisplayName(script)}-pr" + PrintUtils.debug(script, "Create pull request multibranch job ${jobName}") script.folder('pullrequest_jobs') return script.multibranchPipelineJob("pullrequest_jobs/${Utils.getJobDisplayName(script)}-pr")?.with { triggers { @@ -510,4 +511,49 @@ class KogitoJobTemplate { } } + static def createBranchMultibranchPipelineJob(def script, String jobName = '', String jenkinsFilePath = '.ci/jenkins/Jenkinsfile') { + jobName = jobName ?: Utils.getJobDisplayName(script) + PrintUtils.debug(script, "Create branch multibranch job ${jobName}") + script.folder('branch_jobs') + return script.multibranchPipelineJob("branch_jobs/${jobName}")?.with { + triggers { + periodicFolderTrigger { + // The maximum amount of time since the last indexing that is allowed to elapse before an indexing is triggered. + interval('5m') + } + } + factory { + workflowBranchProjectFactory { + scriptPath(jenkinsFilePath) + } + } + branchSources { + github { + id(Utils.getRepoName(script)) // IMPORTANT: use a constant and unique identifier + repoOwner(Utils.getGitAuthor(script)) + repository(Utils.getRepoName(script)) + checkoutCredentialsId(Utils.getGitAuthorCredsId(script)) + scanCredentialsId(Utils.getGitAuthorCredsId(script)) + // Build fork PRs (unmerged head). + buildForkPRHead(false) + // Build fork PRs (merged with base branch). + buildForkPRMerge(false) + // Build origin branches. + buildOriginBranch(true) + // Build origin branches also filed as PRs. + buildOriginBranchWithPR(false) + // Build origin PRs (unmerged head). + buildOriginPRHead(false) + // Build origin PRs (merged with base branch). + buildOriginPRMerge(false) + } + } + orphanedItemStrategy { + discardOldItems { + daysToKeep(10) + } + } + } + } + } From 18f8d03c12a4c4fc4d4b21df9ad869e8228fd107 Mon Sep 17 00:00:00 2001 From: Tristan Radisson Date: Wed, 13 Sep 2023 14:35:56 +0200 Subject: [PATCH 2/2] Update .ci/jenkins/config/branch.yaml --- .ci/jenkins/config/branch.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/jenkins/config/branch.yaml b/.ci/jenkins/config/branch.yaml index 5f2805708..ac0c8598c 100644 --- a/.ci/jenkins/config/branch.yaml +++ b/.ci/jenkins/config/branch.yaml @@ -97,6 +97,7 @@ jenkins: builder: # At some point, this image will need to be changed when a release branch is created # but we need to make sure the image exists first ... simple tag before setting up the branch ? + # See https://github.com/kiegroup/kie-issues/issues/551 image: quay.io/kiegroup/kogito-ci-build:main-latest args: -v /var/run/docker.sock:/var/run/docker.sock --group-add docker --group-add input --group-add render default_tools: