Skip to content

Commit

Permalink
Test update status
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste committed Jun 27, 2023
1 parent 58947b9 commit f51ce38
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 19 deletions.
22 changes: 13 additions & 9 deletions .ci/jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pipeline {
script {
clean()

githubscm.checkoutIfExists('kogito-images', getChangeAuthor(), getChangeBranch(), 'kiegroup', getChangeTarget(), true)
githubscm.checkoutIfExists(getRepoName(), getChangeAuthor(), getChangeBranch(), 'kiegroup', getChangeTarget(), true)
}
}
}
Expand Down Expand Up @@ -75,14 +75,10 @@ Closure createBuildAndTestStageClosure(String image) {
buildParams.add(string(name: 'TARGET_BRANCH', value: getChangeTarget()))
buildParams.add(string(name: 'BUILD_KOGITO_APPS_REF', value: getChangeTarget()))

def job = build(job: "kogito-images.build-image", wait: true, parameters: buildParams, propagate: false)
if (job.result != 'SUCCESS') {
if (job.result == 'UNSTABLE') {
unstable("Tests on ${image} seems to have failed")
} else {
error("Error building ${image}. Please check the logs of the job: ${job.absoluteUrl}")
}
}
githubscm.prepareCommitStatusInformationForPullRequest(getRepoName(), getChangeAuthor(), getChangeBranch(), 'kiegroup', getGitAuthorCredentialsId())
githubscm.updateGithubCommitStatus(image, 'PENDING', 'Queued', getRepoName())

build(job: "${getRepoName()}.build-image", wait: false, parameters: buildParams, propagate: false)
}
}
}
Expand Down Expand Up @@ -110,3 +106,11 @@ String getChangeBranch() {
String getChangeTarget() {
return env.ghprbTargetBranch ?: CHANGE_TARGET
}

String getRepoName() {
return env.REPO_NAME
}

String getGitAuthorCredentialsId() {
return env.AUTHOR_CREDS_ID
}
51 changes: 42 additions & 9 deletions .ci/jenkins/Jenkinsfile.build-image
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Library('jenkins-pipeline-shared-libraries')_
@Library('jenkins-pipeline-shared-libraries')_

QUAY_REGISTRY = 'quay.io'

Expand Down Expand Up @@ -34,16 +34,18 @@ pipeline {
clean()

assert getBuildImageName() : 'Please provide `BUILD_IMAGE_NAME` parameter'

currentBuild.displayName = params.DISPLAY_NAME ?: currentBuild.displayName

if (getTargetBranch()) {
echo "Got a target branch ... Trying to merge the source with the target"
githubscm.checkoutIfExists(getRepoName(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getTargetBranch(), true)
echo 'Got a target branch ... Trying to merge the source with the target'
githubscm.checkoutIfExists(getRepoName(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getTargetBranch(), true, [ token: getGitAuthorTokenCredentialsId(), usernamePassword: getGitAuthorCredentialsId() ])
githubscm.prepareCommitStatusInformationForPullRequest(getRepoName(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getGitAuthorCredentialsId())
} else {
echo "No target branch ... Checking out simply"
checkout(githubscm.resolveRepository(getRepoName(), getSourceAuthor(), getSourceBranch(), false))
echo 'No target branch ... Checking out simply'
checkout(githubscm.resolveRepository(getRepoName(), getSourceAuthor(), getSourceBranch(), false, getGitAuthorCredentialsId()))
githubscm.prepareCommitStatusInformation(getRepoName(), getSourceAuthor(), getSourceBranch(), getGitAuthorCredentialsId())
}
updateGithubCommitStatus('PENDING', 'Started')

if (isProdCI()) {
// Prod fix to be able to build the image as a community one
Expand Down Expand Up @@ -95,6 +97,8 @@ pipeline {
stage('Build image') {
steps {
script {
updateGithubCommitStatus('PENDING', 'Build in progress')

cloud.prepareForDockerMultiplatformBuild()
cloud.startLocalRegistry()

Expand Down Expand Up @@ -136,8 +140,8 @@ pipeline {
}
try {
cloud.skopeoCopyRegistryImages(cloud.getReducedTag(getDeployImageTag()), getBuiltImageTag(reducedTag), retries)
} catch(err) {
echo "Reduced tag cannot be applied"
} catch (err) {
echo 'Reduced tag cannot be applied'
}
}
}
Expand Down Expand Up @@ -169,6 +173,8 @@ pipeline {
}
steps {
script {
updateGithubCommitStatus('PENDING', 'Tests in progress')

String testImageTag = "quay.io/kiegroup/${getBuildImageName()}:${getImageVersion()}"
String builtImageTag = getBuiltImageTag()
// Pull and tag to test image
Expand All @@ -191,6 +197,8 @@ pipeline {
post {
always {
script {
updateGithubCommitStatusFromBuildResult()

clean()
}
}
Expand Down Expand Up @@ -307,6 +315,14 @@ String getTargetBranch() {
return params.TARGET_BRANCH
}

String getGitAuthorCredentialsId() {
return env.AUTHOR_CREDS_ID
}

String getGitAuthorTokenCredentialsId() {
return env.AUTHOR_TOKEN_CREDS_ID
}

boolean shouldDeployImage() {
return params.DEPLOY_IMAGE
}
Expand Down Expand Up @@ -345,4 +361,21 @@ boolean isProdCI() {

String getQuarkusPlatformURL() {
return params.QUARKUS_PLATFORM_URL
}
}

def updateGithubCommitStatus(String state, String message) {
githubscm.updateGithubCommitStatus(getBuildImageName(), state, message)
}

def updateGithubCommitStatusFromBuildResult() {
githubscm.updateGithubCommitStatusFromBuildResult(getBuildImageName())
}

Map getRepositoryInfo() {
return [
repository: getRepoName(),
author: getSourceAuthor(),
branch: getSourceBranch(),
credentials_id: getGitAuthorCredentialsId(),
]
}
10 changes: 9 additions & 1 deletion .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ void setupPrJob(boolean isProdCI = false) {
run_only_for_branches: [ "${GIT_BRANCH}" ],
disable_status_message_error: true,
disable_status_message_failure: true,
commitContext: 'Check Images',
contextShowtestResults: false,
])
if (isProdCI) {
jobParams.job.name += '.prod'
jobParams.pr.trigger_phrase = '.*[j|J]enkins,?.*(rerun|run) [prod|Prod|PROD].*'
jobParams.pr.trigger_phrase_only = true
jobParams.pr.commitContext = 'Prod'
jobParams.pr.commitContext = '(Prod) Check Images'
jobParams.env.put('PROD_CI', true)
}
jobParams.env.putAll([
AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
])
KogitoJobTemplate.createPRJob(this, jobParams)
}

Expand Down Expand Up @@ -178,6 +183,9 @@ void setupBuildImageJob(JobType jobType, String envName = '', boolean prodCI = f
MAX_REGISTRY_RETRIES: 3,
TARGET_AUTHOR: Utils.getGitAuthor(this), // In case of a PR to merge with target branch
PROD_CI: prodCI,

AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
AUTHOR_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
])
KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
logRotator {
Expand Down
1 change: 1 addition & 0 deletions kogito-data-index-postgresql-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version: "2.0.0-snapshot"
from: "registry.access.redhat.com/ubi8/ubi-minimal:latest"
description: "Runtime image for Kogito Data Index Service for PostgreSQL persistence provider"


labels:
- name: "org.kie.kogito.version"
value: "2.0.0-SNAPSHOT"
Expand Down

0 comments on commit f51ce38

Please sign in to comment.