From 5461d267aadbdb06fdfae55e1babcc7a3519d1bf Mon Sep 17 00:00:00 2001 From: radtriste Date: Thu, 22 Jun 2023 15:11:48 +0200 Subject: [PATCH] Test update status --- .ci/jenkins/Jenkinsfile.build-image | 63 ++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/.ci/jenkins/Jenkinsfile.build-image b/.ci/jenkins/Jenkinsfile.build-image index 9de3849bd..efa450ba2 100644 --- a/.ci/jenkins/Jenkinsfile.build-image +++ b/.ci/jenkins/Jenkinsfile.build-image @@ -1,4 +1,4 @@ - @Library('jenkins-pipeline-shared-libraries')_ +@Library('jenkins-pipeline-shared-libraries')_ QUAY_REGISTRY = 'quay.io' @@ -33,15 +33,19 @@ pipeline { script { clean() + sh 'printenv' + + setupGithubCommitStatus() + 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" + echo 'Got a target branch ... Trying to merge the source with the target' githubscm.checkoutIfExists(getRepoName(), getSourceAuthor(), getSourceBranch(), getTargetAuthor(), getTargetBranch(), true) } else { - echo "No target branch ... Checking out simply" + echo 'No target branch ... Checking out simply' checkout(githubscm.resolveRepository(getRepoName(), getSourceAuthor(), getSourceBranch(), false)) } @@ -106,6 +110,8 @@ pipeline { dir('target/image') { cloud.dockerBuildMultiPlatformImages(getBuiltImageTag(), getImageBuildPlatforms(), shouldDeployImage(), squashMessage) } + + updateGithubCommitStatus() } } } @@ -136,8 +142,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' } } } @@ -345,4 +351,49 @@ boolean isProdCI() { String getQuarkusPlatformURL() { return params.QUARKUS_PLATFORM_URL -} \ No newline at end of file +} + +////////////////////////////////////////////////////////////////////////// +// Update commit status + +def getRepoURL() { + String url = sh(returnStdout: true, script: 'git config --get remote.origin.url').trim() + echo "Got Repo URL -> ${url}" + return url +} + +def getCommitSha() { + String sha = sh(returnStdout: true, script: "git show-ref -s ${getSourceBranch()}").trim() + echo "Got Commit SHA -> ${sha}" + return sha +} + +def setupGithubCommitStatus() { + step([ + $class: 'GitHubSetCommitStatusBuilder', + contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "simple-test"], + statusMessage: [ content : 'Hello' ] + ]) +} + +def updateGithubCommitStatus() { + // workaround https://issues.jenkins-ci.org/browse/JENKINS-38674 + repoUrl = getRepoURL() + commitSha = getCommitSha() + + step([ + $class: 'GitHubCommitStatusSetter', + commitShaSource: [$class: 'ManuallyEnteredShaSource', sha: commitSha], + contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "simple-test"], + errorHandlers: [[$class: 'ShallowAnyErrorHandler']], + reposSource: [$class: 'ManuallyEnteredRepositorySource', url: repoUrl], + statusResultSource: [ + $class: 'ConditionalStatusResultSource', + results: [ + [$class: 'BetterThanOrEqualBuildResult', result: 'SUCCESS', state: 'SUCCESS', message: 'anything'], + [$class: 'BetterThanOrEqualBuildResult', result: 'FAILURE', state: 'FAILURE', message: 'anything'], + [$class: 'AnyBuildResult', state: 'FAILURE', message: 'Loophole'] + ] + ] + ]) +}