Skip to content

Instantly share code, notes, and snippets.

@churowa
Last active August 10, 2017 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save churowa/e250d78d9ee91876849fb77274a0e959 to your computer and use it in GitHub Desktop.
Save churowa/e250d78d9ee91876849fb77274a0e959 to your computer and use it in GitHub Desktop.
function inside a Jenkinsfile, Jenkins complains that `java.lang.NoSuchMethodError: No such DSL method 'anchor' found among steps`
/* The expected JSON:
{
"text": "Division by zero",
"anchor": {
"line": "59",
"path": "App/FifteenMinuteTest.m"
}
}
*/
import groovy.json.JsonBuilder
private String buildJsonCommentFromCompileWarning(warning, baseCodePath) {
def fileDetails = warning.file_path.find(/${baseCodePath}.*/)
def splitFileDetails = fileDetails.split(":")
def line_number = splitFileDetails[1]
def file_path = splitFileDetails[0]
def reason = warning.reason
def builder = new JsonBuilder()
def json = builder {
text reason
anchor {
line line_number
path file_path
}
}
def payload = builder.toString()
echo payload
return payload
}
java.lang.NoSuchMethodError: No such DSL method 'anchor' found among steps [AddInteractivePromotion, ArtifactoryGradleBuild, ArtifactoryMavenBuild, ConanAddRemote, ConanAddUser, InitConanClient.....
@churowa
Copy link
Author

churowa commented Aug 10, 2017

I feel like lines 20-26 should give me the json object I want. However, after running my Jenkinsfile, I get the error at the bottom of the gist.

Isn't this the correct syntax for using JsonBuilder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment