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

[CI] Add error steps and help links to PR comments #60772

Merged
merged 8 commits into from
Mar 23, 2020
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
19 changes: 19 additions & 0 deletions vars/githubPr.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,20 @@ def getNextCommentMessage(previousCommentInfo = [:]) {
## :broken_heart: Build Failed
* [continuous-integration/kibana-ci/pull-request](${env.BUILD_URL})
* Commit: ${getCommitHash()}
* [Pipeline Steps](${env.BUILD_URL}flowGraphTable) (look for red circles / failed steps)
* [Interpreting CI Failures](https://www.elastic.co/guide/en/kibana/current/interpreting-ci-failures.html)
"""

try {
def steps = getFailedSteps()
if (steps?.size() > 0) {
def list = steps.collect { "* [${it.displayName}](${it.logs})" }.join("\n")
messages << "### Failed CI Steps\n${list}"
}
} catch (ex) {
buildUtils.printStacktrace(ex)
print "Error retrieving failed pipeline steps for PR comment, will skip this section"
}
}

messages << getTestFailuresMessage()
Expand Down Expand Up @@ -220,3 +233,9 @@ def deleteComment(commentId) {
def getCommitHash() {
return env.ghprbActualCommit
}

def getFailedSteps() {
return jenkinsApi.getFailedSteps()?.findAll { step ->
step.displayName != 'Check out from version control'
}
}
21 changes: 21 additions & 0 deletions vars/jenkinsApi.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def getSteps() {
def url = "${env.BUILD_URL}api/json?tree=actions[nodes[iconColor,running,displayName,id,parents]]"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating URLs with proper tools looks like this:

def builder = new URIBuilder(env.BUILD_URL)
def url = builder
    .setPathSegments(builder.getPathSegments() + ['api', 'json'])
    .setParameter('tree', 'actions[nodes[iconColor,running,displayName,id,parents]]')
    .toString()

and actually produces incorrectly-formatted URLs, e.g.
https://kibana-ci.elastic.co/job/elastic+kibana+pipeline-pull-request/34782//api/json?tree=actions%5Bnodes%5BiconColor%2Crunning%2CdisplayName%2Cid%2Cparents%5D%5D

(notice the double //)

def responseRaw = httpRequest([ method: "GET", url: url ])
def response = toJSON(responseRaw)

def graphAction = response?.actions?.find { it._class == "org.jenkinsci.plugins.workflow.job.views.FlowGraphAction" }

return graphAction?.nodes
}

def getFailedSteps() {
def steps = getSteps()
def failedSteps = steps?.findAll { it.iconColor == "red" && it._class == "org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode" }
failedSteps.each { step ->
step.logs = "${env.BUILD_URL}execution/node/${step.id}/log".toString()
}

return failedSteps
}

return this