jenkins job dsl - No signature of method: java.lang.String.call() - jenkins

I am unable to run this piece of code:
buildPath = 'applications'
buildJob(['java', 'nodejs'])
def buildJob(def jobList){
for(job in jobList){
def jobName = "${job}_seed"
def jobDescription = "Jenkins DSL seed for ${job}"
def jobScriptPath = "resources/dsl/${jobName}.groovy"
job("${buildPath}/${jobName}")
}
}
So, I am getting this error:
Processing provided DSL script
ERROR: (script, line 12) No signature of method: java.lang.String.call() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [applications/java_seed]
Possible solutions: wait(), any(), wait(long), take(int), each(groovy.lang.Closure), any(groovy.lang.Closure)
Finished: FAILURE
I do not see where or what is causing this error. I created a single job outside of the buildJob(def jobList) function and it is working but I need to do the loop to automation the jobs creation.
Any ideas?

Posting a similar issue i have run into. Isn't much around the web on this issue.
No signature of method: java.lang.String.call() is applicable for argument types: (java.lang.String) values: [some-value]
Say we are implementing a job dsl plugin (https://github.com/jenkinsci/multibranch-build-strategy-extension-plugin) like:
includeRegionBranchBuildStrategy {
includedRegions(String value)
}
And we have code like:
def includedRegions = r ? String.join("\n", r) : null
branchSources {
branchSource {
buildStrategies {
if(includedRegions){
includeRegionBranchBuildStrategy {
includedRegions(includedRegions)
}
}
}
}
}
Need to rename your variable to get it to work! e.g the method can't have the same name as a var defined above.
def regions = r ? String.join("\n", r) : null
branchSources {
branchSource {
buildStrategies {
if(regions){
includeRegionBranchBuildStrategy {
includedRegions(regions)
}
}
}
}
}

you are iterating string array in the following line:
for(job in jobList){
and using variable job for this.
then you try to invoke method call on this variable:
job("${buildPath}/${jobName}")

Related

Jenkinsfile syntax error: No such property

I'm trying to test a binary with latest commit id in Jenkins. Error happens at send slack message stage:
def kResPath = "/tmp/res.json" // global variable, where json file is dumped to; declared at the very beginning of Jenkinsfile
def check_result_and_notify(tier, result) {
def kExpected = 3
def kSuccessSlackColor = "#00CC00"
message = "Test ${tier} result: ${result}\n"
def test_result = readJSON file: kResPath
// 0 means index, "benchmarks", "real-time" is the key
real_time = test_result["benchmarks"][0]["real_time"]
if (real_time > kExpected) {
message += String.format("real time = %f, expected time = %f", real_time, kExpected)
}
slackSend(color: ${kSuccessSlackColor}, message: message.trim(), channel: "test-result")
}
The json file looks like:
{
"benchmarks": [
{
"real_time": 4,
},
{
"real_time": 5,
}
],
}
The error message I've received is hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: kResPath for class: WorkflowScript
Can someone tell me what's wrong with my code?
Is there any way I could test it locally so that I don't need to commit it every single time? I googled and find it needs server id and password, which I don't think accessible to me :(
Your kResPath variable is undefined in the scope of that function or method (unsure which based on context). You can pass it as an argument:
def check_result_and_notify(tier, result, kResPath) {
...
}
check_result_and_notify(myTier, myResult, kResPath)
and even specify a default if you want:
def check_result_and_notify(tier, result, kResPath = '/tmp/res.json')

JobDSL triggers deprecated, pipelineTriggers closure problem

I'm using jobdsl 1.76 and trying to migrate to 1.77: from triggers to pipelineTriggers:
pipelineJob('testPipelineTriggers'){
properties {
pipelineTriggers {
triggers {
cron{
spec("* * * * *")
}
}
}
}
}
This simple code giving me below error which I couldnt understand:
No signature of method: javaposse.jobdsl.dsl.helpers.properties.PropertiesContext.pipelineTriggers() is applicable for argument types: (XXX$__clinit__closure1$_closure2$_closure7$_closure9) values: [XXX$__clinit__closure1$_closure2$_closure7$_closure9#3c818ac4]
note: I replaced our groovy filename with 'XXX'

Can config slurper parse methods with map as input variable

I am trying to parse a groovy file using config slurper like this .
fileContents = '''deployment {
deployTo('dev') {
test = me
}
}'''
def config = new ConfigSlurper().parse(fileContents)
The above code works because the deployto('dev') is simply accepting a string. But I add an extra parameter to it , it fails with this exception:
fileContents = '''deployment {
deployTo('dev','qa') {
test = me
}
}'''
def config = new ConfigSlurper().parse(fileContents)
It fails with the following exception :
Caught: groovy.lang.MissingMethodException: No signature of method: groovy.util.ConfigSlurper$_parse_closure5.deployTo() is applicable for argument types: (java.lang.String, java.lang.String, script15047332444361539770645$_run_closure3$_closure10) values: [dev, postRun, script15047332444361539770645$_run_closure3$_closure10#6b8ca3c8]
Is there a way around reading this config file with extra args in a module?
You are almost there. In order to use list of values, please do the below change.
From:
deployTo('dev','qa')
To:
deployTo(['dev','qa'])
It would be:
def fileContents = '''deployment { deployTo(['dev','qa']) { test = me } }'''
def config = new ConfigSlurper().parse(fileContents)​

Grails custom test - No signature of method: org.codehaus.groovy.grails.test.runner.phase.IntegrationTestPhaseConfigurer.prepare()

I'm trying to follow Luke Daley's instructions on http://ldaley.com/post/615966534/custom-grails-test to add a custom test type, which should behave as an integration spec (grails-2.4.4, btw).
I've put my specs under test/apint and my _Events.groovy loooks like below:
eventAllTestsStart = {
phasesToRun << "apint"
}
def apintSpecsSuffix = "spec"
def apintSpecsDirectory = "apint"
def apintSpecsTestType = new GrailsSpecTestType(apintSpecsSuffix, apintSpecsDirectory)
apintTests = [apintSpecsTestType]
apintTestPhasePreparation = {
integrationTestPhasePreparation()
}
apintTestPhaseCleanUp = {
integrationTestPhaseCleanUp()
}
When I run grails test-app apint: I get the following error message:
Fatal error running tests: No signature of method: org.codehaus.groovy.grails.test.runner.phase.IntegrationTestPhaseConfigurer.prepare() is applicable for argument types: () values: []
Possible solutions: prepare(groovy.lang.Binding, java.util.Map), prepare(groovy.lang.Binding, java.util.Map), grep(), grep(java.lang.Object), every(), println() (Use --stacktrace to see the full trace)
.Tests FAILED
Any ideas why this is happening or how to fix it?
Thanks!

Grails 2.2.1 groupProperty on Integration tests

For some reason the groupProperty is not working on my integration tests. I'm getting the following exception:
groovy.lang.MissingMethodException: No signature of method:
mypackage.CarIntTests.groupProperty() is applicable for argument
types: (java.lang.String) values: [car]
def names = ['Honda', 'Toyota', 'Nissan']
3.times {
Garage.build(name: names[it])
}
def results = Garage.withCriteria {
car {
eq('brand', 'Honda')
}
projections {
groupProperty('car')
}
}
assert results == names[0..0]

Resources