Skip to content

Commit

Permalink
Set GitHub commit status for downstream PR tester jobs (#2459)
Browse files Browse the repository at this point in the history
* try status

* try again

* another try

* try again

* more logic

* add context

* more context

* add context to readfile

* move updateGithubCommitStatus

* one more try

* try again

* add logs

* add url

* try again

* dd job name

* testing

* final changes

* final fixes

* improvement

* try adding pending

* testing
  • Loading branch information
gdams authored Feb 8, 2021
1 parent eacc106 commit dd651a5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
62 changes: 62 additions & 0 deletions pipelines/build/common/openjdk_build_pipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,10 @@ class Build {
context.withEnv(envVars) {
try {
context.timeout(time: buildTimeouts.BUILD_JDK_TIMEOUT, unit: "HOURS") {
// Set Github Commit Status
if (env.JOB_NAME.contains("pr-tester")) {
updateGithubCommitStatus("PENDING", "Build Started")
}
if (useAdoptShellScripts) {
context.println "[CHECKOUT] Checking out to AdoptOpenJDK/openjdk-build to use their bash scripts..."
repoHandler.checkoutAdopt()
Expand All @@ -978,6 +982,10 @@ class Build {
}
}
} catch (FlowInterruptedException e) {
// Set Github Commit Status
if (env.JOB_NAME.contains("pr-tester")) {
updateGithubCommitStatus("FAILED", "Build FAILED")
}
throw new Exception("[ERROR] Build JDK timeout (${buildTimeouts.BUILD_JDK_TIMEOUT} HOURS) has been reached. Exiting...")
}

Expand Down Expand Up @@ -1006,6 +1014,10 @@ class Build {
}
}
} catch (FlowInterruptedException e) {
// Set Github Commit Status
if (env.JOB_NAME.contains("pr-tester")) {
updateGithubCommitStatus("FAILED", "Build FAILED")
}
throw new Exception("[ERROR] Build archive timeout (${buildTimeouts.BUILD_ARCHIVE_TIMEOUT} HOURS) has been reached. Exiting...")
}
} finally {
Expand All @@ -1030,9 +1042,17 @@ class Build {
}
}
} catch (FlowInterruptedException e) {
// Set Github Commit Status
if (env.JOB_NAME.contains("pr-tester")) {
updateGithubCommitStatus("FAILED", "Build FAILED")
}
throw new Exception("[ERROR] AIX clean workspace timeout (${buildTimeouts.AIX_CLEAN_TIMEOUT} HOURS) has been reached. Exiting...")
}
}
// Set Github Commit Status
if (env.JOB_NAME.contains("pr-tester")) {
updateGithubCommitStatus("SUCCESS", "Build PASSED")
}
}
}
}
Expand Down Expand Up @@ -1076,6 +1096,41 @@ class Build {
}
}


def getRepoURL() {
context.sh "git config --get remote.origin.url > .git/remote-url"
return context.readFile(".git/remote-url").trim()
}

def getCommitSha() {
context.sh "git rev-parse HEAD > .git/current-commit"
return context.readFile(".git/current-commit").trim()
}

def updateGithubCommitStatus(STATE, MESSAGE) {
// workaround https://issues.jenkins-ci.org/browse/JENKINS-38674
def repoUrl = getRepoURL()
def commitSha = getCommitSha()

String shortJobName = env.JOB_NAME.split('/').last()

context.println "Setting GitHub Checks Status:"
context.println "REPO URL: ${repoUrl}"
context.println "COMMIT SHA: ${commitSha}"
context.println "STATE: ${STATE}"
context.println "MESSAGE: ${MESSAGE}"
context.println "JOB NAME: ${shortJobName}"

context.step([
$class: 'GitHubCommitStatusSetter',
reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commitSha],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: shortJobName],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [$class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: MESSAGE, state: STATE]] ]
])
}

/*
Main function. This is what is executed remotely via the helper file kick_off_build.groovy, which is in turn executed by the downstream jobs.
*/
Expand Down Expand Up @@ -1107,6 +1162,13 @@ class Build {
*/
context.library(identifier: 'openjdk-jenkins-helper@master')

// Set Github Commit Status
if (env.JOB_NAME.contains("pr-tester")) {
context.node('master') {
updateGithubCommitStatus("PENDING", "Pending")
}
}

if (buildConfig.DOCKER_IMAGE) {
// Docker build environment
def label = buildConfig.NODE_LABEL + "&&dockerBuild"
Expand Down
2 changes: 2 additions & 0 deletions pipelines/src/main/groovy/testDoubles/ContextStub.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class ContextStub {

String checkout(String s) {}

String step(Map<String, ?> s) {}

String checkout(Map<String, ?> s) {}

String writeFile(Map s) {}
Expand Down

0 comments on commit dd651a5

Please sign in to comment.