I just want to use triggerPhrase to trigger my jenkins pipeline if you give the comment such as "Rebuild"
triggerPhrase('Rebuild')
but I got this error
No signature of method: javaposse.jobdsl.dsl.helpers.triggers.TriggerContext.triggerPhrase() is applicable for argument types: (java.lang.String) values: [Rebuild]
any solutions?
Related
From jenkins script console, how can I initiate a build for a job?
Tried:
for(job in Hudson.instance.getView(view_name).items) {
job.startBuild()
}
Error:
groovy.lang.MissingMethodException: No signature of method: hudson.model.FreeStyleProject.startBuild() is applicable for argument types: () values: []
You can use run.scheduleBuild, as example
cause = new hudson.model.Cause.RemoteCause(startServer, startNote)
failedRuns.each{run -> run.scheduleBuild(cause)}
I'm a newbie at Jenkins job-dsl scripting.
I'm working to convert the Jenkins XML configuration to Groovy DSL script using a plugin (https://github.com/AOEpeople/gradle-jenkins-job-dsl-plugin) that uses Gradle tool for building the script and running Unit Test locally.
However, currently, I'm facing an issue with the extension DSL from a 3rd Party Jenkins Plugin (https://github.com/jenkinsci/ghprb-plugin).
triggers {
githubPullRequest {
orgWhitelist("Test")
cron("H/5 * * * *")
extensions {
commitStatus {
completedStatus('SUCCESS', 'Build succeeded.')
completedStatus('FAILURE', 'Build failed.')
}
}
}
}
The script cannot be generated by Gradle because of the issue:
Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslScriptException'
at spock.lang.Specification.noExceptionThrown(Specification.java:119)
at com.aoe.gradle.jenkinsjobdsl.JobScriptsSpec.test DSL script #file.name(JobScriptsSpec.groovy:55)
Caused by: javaposse.jobdsl.dsl.DslScriptException: (PullRequestJobTemplate.groovy, line 59) No signature of method: static org.apache.commons.lang.ClassUtils.isAssignable() is applicable for argument types: ([Ljava.lang.Class;, [Ljava.lang.Class;, java.lang.Boolean) values: [[class com.unified.dsl.templates.PullRequestJobTemplate$_closure1$_closure5$_closure15], ...]
Possible solutions: isAssignable([Ljava.lang.Class;, [Ljava.lang.Class;), isAssignable(java.lang.Class, java.lang.Class)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:107)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts_closure1(AbstractDslScriptLoader.groovy:60)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:46)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:81)
at com.aoe.gradle.jenkinsjobdsl.JobScriptsSpec.test DSL script #file.name(JobScriptsSpec.groovy:51)
Caused by: groovy.lang.MissingMethodException: No signature of method: static org.apache.commons.lang.ClassUtils.isAssignable() is applicable for argument types: ([Ljava.lang.Class;, [Ljava.lang.Class;, java.lang.Boolean) values: [[class com.unified.dsl.templates.PullRequestJobTemplate$_closure1$_closure5$_closure15], ...]
Possible solutions: isAssignable([Ljava.lang.Class;, [Ljava.lang.Class;), isAssignable(java.lang.Class, java.lang.Class)
at javaposse.jobdsl.plugin.ExtensionPointHelper.findExtensionPoints_closure1(ExtensionPointHelper.groovy:24)
at javaposse.jobdsl.plugin.ExtensionPointHelper.findExtensionPoints(ExtensionPointHelper.groovy:23)
at javaposse.jobdsl.plugin.JenkinsJobManagement.callExtension(JenkinsJobManagement.java:365)
at javaposse.jobdsl.dsl.AbstractExtensibleContext.methodMissing(AbstractExtensibleContext.groovy:17)
at com.unified.dsl.templates.PullRequestJobTemplate.closure1$_closure5(PullRequestJobTemplate.groovy:59)
at com.unified.dsl.templates.PullRequestJobTemplate.closure1$_closure5(PullRequestJobTemplate.groovy)
at javaposse.jobdsl.dsl.ContextHelper.executeInContext(ContextHelper.groovy:16)
at javaposse.jobdsl.dsl.Job.triggers(Job.groovy:568)
at com.unified.dsl.templates.PullRequestJobTemplate$_closure1.doCall(PullRequestJobTemplate.groovy:58)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at groovy.lang.Closure.call(Closure.java:430)
at javaposse.jobdsl.dsl.JobParent.processItem(JobParent.groovy:114)
at javaposse.jobdsl.dsl.JobParent.freeStyleJob(JobParent.groovy:47)
at com.unified.dsl.base.JobBuilder.build(JobBuilder.groovy:52)
at stage.script.run(script:12)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:124)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:101)
... 6 more
So the stacktrace you are getting is being generated by the Spock Test that checks to see if the job-dsl script compiles. So you have set up your development environment correctly! Always a good start.
Now all you need to do is setup your local Jenkins runtime to allow the Jenkins XML config file to be generated when it is kicked off by the Spock Test.
Reviewing your job-dsl script I must say it looks good to me. Specifically I compared it to the complete sample job-dsl on the GitHub pull request builder plugin's home page ...
https://wiki.jenkins.io/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-JobDSLSupport
The key part of the stack trace is this line here
PullRequestJobTemplate.groovy, line 59) No signature of method:
static org.apache.commons.lang.ClassUtils.isAssignable() is applicable
for argument types: ([Ljava.lang.Class;, [Ljava.lang.Class;,
java.lang.Boolean) values: [[class com.unified.dsl.templates.PullRequestJobTemplate$_closure1$_closure5$_closure15], ...]
To me this would indicate that there was still a run-time dependency missing to allow the GH PR Builder plugin job-dsl to run as expected.
Further reviewing the plugin page I note that the following dependencies are variously required and optional ...
credentials (version:1.21)
matrix-project (version:1.6)
build-flow-plugin (version:0.12, optional)
ssh-agent (version:1.3)
structs (version:1.6)
github (version:1.26.0)
git (version:2.4.0)
github-api (version:1.82)
plain-credentials (version:1.1)
job-dsl (version:1.39, optional)
token-macro (version:1.10, optional)
If you add these to the Gradle build then I would say that your XML will be generated.
Don't forget to add these dependencies to the target Jenkins server when you have completed your job-dsl development.
I have some groovy script for generating jenkins jobs, which worked great.
But after reinstallation of jenkins this script throws exception.
problem part of script is:
publishers {
allure(['path-to/reports'])
}
And error is:
Processing DSL script seed.groovy
ERROR: (JobBuilder.groovy, line 55) No signature of method:
javaposse.jobdsl.dsl.helpers.publisher.PublisherContext.allure() is
applicable for argument types: (java.util.ArrayList) values:
[[PyUIAutotest/reports]]
Possible solutions: mailer(java.lang.String),
use([Ljava.lang.Object;), asType(java.lang.Class)
Finished: FAILURE
It fails on wrong signature of method, but it is correct, and i don't know what is wrong.
example of script available on wiki dock. and javadoc for allure() method
Jenkins ver. 2.46.2; Job DSL ver. 1.63, Allure-Jenkins-Plugin ver. 2.15
weird thing in that, i have another server with same plugin versions, and it works fine
Instead of
publishers {
allure(['path-to/reports'])
}
use this syntax (which you can also generate using Jenkins pipeline-syntax generator):
allure([includeProperties: false, jdk: '', properties: [], reportBuildPolicy: 'ALWAYS', results: [[path: 'path-to/reports']]])
You might find my answer here useful: https://stackoverflow.com/a/71082002/1169433
In short, you may need to add the allure-jenkins-plugin in your build dependencies.
I am trying to execute below commands in Jenkins groovy script.
import hudson.model.*
def buildA = build("Master-Build")
println(buildA.getProject().getLastSuccessfulBuild())
and I am getting below errors
00:00:00.652 FATAL: No signature of method:
hudson.model.FreeStyleBuild.call() is applicable for argument types:
(java.lang.String) values: [Master-Build] 00:00:00.652 Possible
solutions: wait(), save(), any(), wait(long),
each(groovy.lang.Closure), any(groovy.lang.Closure) 00:00:00.652
groovy.lang.MissingMethodException: No signature of method:
hudson.model.FreeStyleBuild.call() is applicable for argument types:
(java.lang.String) values: [Master-Build]
How can I fix this?
Looking at the error it looks like you are calling Execute system Groovy script build step in a freestyle build. When you use groovy in that step, then the variable build is predefined to the current build and not a function for building other jobs (you might have confused it with the predefined functions/variables in Build Flow Job where the build variable is a function which starts a new build).
So in order to start a new build, you need to access the Jenkins instance directly and tell it to start a new job (inspired by this script):
// Import Jenkins
import jenkins.model.Jenkins;
// Get Jenkins instance
def j = Jenkins.getInstance();
// Get the job we wan't to trigger
def job = j.getItem("B");
// Finally we schedule a new build which starts directly (the zero in the argument)
job.scheduleBuild2(0)
Please help me, I'm trying to change the number of executors on jenkins. When I'm running this code, it works:
import jenkins.model.Jenkins
Jenkins jenkins = Jenkins.getInstance()
jenkins.setNumExecutors(4)
jenkins.save()
When I use the next function:
void set_executors(int number) {
Jenkins jenkins = Jenkins.getInstance()
jenkins.setNumExecutors(number)
jenkins.save()
}
And running:
java -jar jenkins-cli.jar -s http://localhost:8080 groovy /var/lib/jenkins/executor.groovy set_executors 4
I'm getting:
groovy.lang.MissingMethodException: No signature of method:
Actions.set_executors() is applicable for argument types
(java.lang.String) values: [4]
Possible solutions: set_executors(int)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
Please help!
When run from the command line, groovy passes arguments as strings. Your set_executors function is being called with a String argument instead of an integer as the function expects. You need to modify your code to accept a String argument and convert it to an integer.