No signature of method when trying to build job using groovy

167 views
Skip to first unread message

Gopi V

unread,
May 17, 2021, 7:49:05 PM5/17/21
to job-dsl-plugin

I'm getting below error when I'm running below seed job

ERROR: Build step failed with exception groovy.lang.MissingMethodException: No signature of method: java.lang.Class.buildJob() is applicable for argument types: (Script1, java.lang.String, java.lang.String, java.lang.String) values: [Script1@4e13abe2, job1, Test job, ...] at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:153) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161) at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165) at org.kohsuke.groovy.sandbox.impl.Checker$checkedCall$1.callStatic(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194) at Script1.run(Script1.groovy:30) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runScript(GroovySandbox.java:162) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:370) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:314)


seed job:

import java.util.logging.Logger

Logger logger = Logger.getLogger('org.example.jobdsl')

def parent = getClass().getClassLoader()
def loader = new GroovyClassLoader(parent)
File sourceFile = new File("jenkins_home/jobs/dsl_scripts/SimpleMultibranchPipelineJobSingleSource.groovy")
Class SimpleMultibranchPipelineJobSingleSource = loader.parseClass(sourceFile)
logger.info("class: ${SimpleMultibranchPipelineJobSingleSource}")
SimpleMultibranchPipelineJobSingleSource.buildJob(
    this,
    "job1",
    "Test job",
    "jenkinsfile")



SimpleMultibranchPipelineJobSingleSource.groovy file:

import javaposse.jobdsl.dsl.DslFactory
// import javaposse.jobdsl.dsl.Job
// import javaposse.jobdsl.dsl.jobs.MultibranchWorkflowJob
import java.util.logging.Logger


class SimpleMultibranchPipelineJobSingleSource {
  static buildJob(
    DslFactory dslFactory,
    String name,
    String desc,
    String jenkinsfile_path) {
    Logger logger = Logger.getLogger('org.example.jobdsl')
    logger.info(" dsl factory: ${dslFactory}")
    def source_id = UUID.randomUUID().toString()
    def git_data = [
      repo_remote: 'g...@github.com:**/**.git',
      repo_cred_id: '***',
      includes_branches: '***',
      excludes_branches: ''
    ]

    logger.info("jobs name: ${name}")
    dslFactory.multibranchPipelineJob(name) {
      description(desc)
      branchSources {
        branchSource {
          source {
            git {
              remote(git_data['repo_remote'])
              credentialsId(git_data['repo_cred_id'])
              id(source_id)
              traits {
                gitBranchDiscovery()
                headWildcardFilter {
                  includes(git_data['includes_branches'])
                  excludes(git_data['excludes_branches'])
                }
              }
            }
          }
          strategy {
            allBranchesSame {
              props {
                // Suppresses the normal SCM commit trigger coming from branch indexing.
                suppressAutomaticTriggering()
              }
            }
          }
        }
      }
      factory {
        workflowBranchProjectFactory {
          scriptPath(jenkinsfile_path)
        }
      }
      orphanedItemStrategy {
        discardOldItems {
          daysToKeep(-1)
          numToKeep(30)
        }
      }
    }
  }
}


Gopi V

unread,
May 17, 2021, 11:48:23 PM5/17/21
to job-dsl-plugin
Any help here is appreciated. 
Reply all
Reply to author
Forward
0 new messages