Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create multibranch kogito-ci-build image job #1084

Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
"""
}
}
Expand Down
5 changes: 4 additions & 1 deletion .ci/jenkins/config/branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ 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 ?
# See https://github.com/kiegroup/kie-issues/issues/551
image: quay.io/kiegroup/kogito-ci-build:main-latest
radtriste marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
28 changes: 15 additions & 13 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
])
Expand All @@ -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',
Expand All @@ -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}",

Expand All @@ -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}",

Expand All @@ -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}",
Expand All @@ -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}",

Expand Down Expand Up @@ -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}",
Expand All @@ -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}",

Expand All @@ -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}",

Expand Down Expand Up @@ -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)
}

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
}

}