script using "slackNotifier" causes MissingMethodException if the script is run locally

746 views
Skip to first unread message

Ulrich Winter

unread,
Oct 14, 2016, 12:32:52 PM10/14/16
to job-dsl-plugin
Hi,

as described in 
I want to run a new jobdsl groovy script locally before running it inside our productive jenkins.

This works fine.

But jobdsl scripts using "slackNotifier" publisher cause the following error, if they are run locally:

Caused by: javaposse.jobdsl.dsl.DslScriptException: (test.groovy, line 31) No signature of method: javaposse.jobdsl.dsl.helpers.publisher.PublisherContext.slackNotifier() is applicable for argument types: (test$_run_closure1_closure5_closure10) values: [test$_run_closure1_closure5_closure10@1e4a7dd4]
Possible solutions: stashNotifier(), stashNotifier(groovy.lang.Closure)

Those scripts work fine if I run them inside jenkins.
I also tried to add slack.jar from https://updates.jenkins-ci.org/latest/slack.hpi to the classpath, but that didn't help.

Here's a sample script causing this error:


--- start ---
import javaposse.jobdsl.dsl.helpers.publisher.PublisherContext


job("test") {
    description('This job is generated and managed by the job dsl plugin. Do not modify this job manually. ')
    scm {
        git {
            remote {
                url("ssh://g...@somewhere.com:7999/project/test.git")
                credentials('xxx')
            }
            branch("master")
            extensions {
                localBranch("master")
            }
        }
    }
    triggers {
        scm('@daily')
    }
    steps {
        gradle {
            useWrapper()
            makeExecutable()
            tasks("clean build publish")
            switches('--refresh-dependencies')
        }
    }
    publishers {
        slackNotifier {
            notifyAborted(true)
            notifyBackToNormal(true)
            notifyFailure(true)
            notifyRepeatedFailure(true)
            notifyNotBuilt(true)
            notifyUnstable(true)
            notifySuccess(false)
            startNotification(false)
            includeTestSummary(false)
            includeCustomMessage(false)
            customMessage(null)
            commitInfoChoice('AUTHORS_AND_TITLES')
            room('#jenkins')
            buildServerUrl('http://jenkins.somewhere.com/')
            teamDomain('myteam')
            authToken('xxx')
            sendAs(null)
        }
    }
}
--- end ---



Does somebody know what to do to run such a script locally?


Thank you in advance,

Ulrich

Victor Martinez

unread,
Oct 14, 2016, 4:52:29 PM10/14/16
to job-dsl-plugin
Try the below project:

Then  you can use the debugXml task

thomas....@gmail.com

unread,
Oct 15, 2016, 7:55:12 AM10/15/16
to job-dsl-plugin
Hi,


as a consequence, you cannot run a script including slackNotifier (or other auto-generated method) locally as easily as other scripts.

To do this, you have to run an emulated Jenkins in memory with slack plugin pre-installed.

As Victor told you, the sheehan's repo is perfect to test your scripts locally (either with auto-generated parts or not).

The debugXml task won't work with auto-generated DSL though. I think I'll propose a PR for this soon (dirty but it works)

Ulrich Winter

unread,
Oct 18, 2016, 3:11:54 AM10/18/16
to job-dsl-plugin
Hi Victor, Thomas,


the gradle-example encounters the same problem within its example9:

./gradlew debugXml -Dpattern=jobs/**/example9Jobs.groovy


causes an exception:

Exception in thread "main" javaposse.jobdsl.dsl.DslScriptException: (script, line 10) No signature of method: javaposse.jobdsl.dsl.helpers.ScmContext.cvsscm() is applicable for argument types: (script$_run_closure2$_closure3$_closure6) values: [script$_run_closure2$_closure3$_closure6@5170bcf4]


So what is the preferred (non dirty) solution to check  a given jobdsl script which uses an autogenerated API?



Regards,


Ulrich


Victor Martinez

unread,
Oct 18, 2016, 1:05:17 PM10/18/16
to job-dsl-plugin
As Thomas mentioned, debugXml won't work with autogenerated API. You could use clean test to confirm it works fine as long as you set those spock tests. Besides of that, have you tried to configure those test plugin dependencies?


in your case:

testPlugins 'org.jenkins-ci.plugins:slack:2.0.1'
testPlugins 'org.jenkins-ci.plugins:cvs:2.12'

Although I'm not using autogenerated dsl yet in any of my prod environments, you might test out the above suggestion, or maybe someone else knows another approach

Cheers

Victor Martinez

unread,
Oct 18, 2016, 5:09:40 PM10/18/16
to job-dsl-plugin
Forget about what I said, since it's a known issue:


Cheers

Matt Sheehan

unread,
Oct 24, 2016, 2:24:42 PM10/24/16
to job-dsl-plugin
FYI - in the latest version of the job-dsl-gradle-example the debugXml task has been removed. Instead the JobScriptsSpec (which supports the autogenerated API) will now create the XML files and write them to to ./build/debug-xml. Thanks to Thomas for the PR.



--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/31537139-087f-4860-b4ee-d0c1dfe056dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Martinez

unread,
Oct 24, 2016, 5:25:55 PM10/24/16
to job-dsl-plugin
Awesome, Thanks Matt
Reply all
Reply to author
Forward
0 new messages