0

This is what I have in my shared library file

build job: 'Job Name',
          parameters:
          [
               string(name: 'ENVIRONMENT', value: 'sit'),
               string(name: 'param1', value: 'value1' )
          ]

It is failing with below error :

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: build.call() is applicable for argument types: (java.util.LinkedHashMap) values: [[job:**********, parameters:[@string(name=ENVIRONMENT,value=sit), ...]]]
Possible solutions: call(java.lang.Object, java.lang.Object, java.lang.Object), wait(), any(), wait(long), main([Ljava.lang.String;), any(groovy.lang.Closure)

Any help here?

Nicola Ben
  • 10,615
  • 8
  • 41
  • 65
Avadh
  • 51
  • 1
  • 3
  • 10

3 Answers3

1

Library classes cannot directly call steps such as sh or git. They can however implement methods, outside of the scope of an enclosing class, which in turn invoke Pipeline steps, for example:

// src/org/foo/Zot.groovy
package org.foo;

def checkOutFrom(repo) {
  git url: "git@github.com:jenkinsci/${repo}"
}

return this

Which can then be called from a Scripted Pipeline:

def z = new org.foo.Zot()
z.checkOutFrom(repo)

This approach has limitations; for example, it prevents the declaration of a superclass.

Alternately, a set of steps can be passed explicitly using this to a library class, in a constructor, or just one method:

package org.foo
class Utilities implements Serializable {
  def steps
  Utilities(steps) {this.steps = steps}
  def mvn(args) {
    steps.sh "${steps.tool 'Maven'}/bin/mvn -o ${args}"
  }
}

When saving state on classes, such as above, the class must implement the Serializable interface. This ensures that a Pipeline using the class, as seen in the example below, can properly suspend and resume in Jenkins.

@Library('utils') import org.foo.Utilities
def utils = new Utilities(this)
node {
  utils.mvn 'clean package'
}

If the library needs to access global variables, such as env, those should be explicitly passed into the library classes, or methods, in a similar manner.

Instead of passing numerous variables from the Scripted Pipeline into a library,

package org.foo
class Utilities {
  static def mvn(script, args) {
    script.sh "${script.tool 'Maven'}/bin/mvn -s ${script.env.HOME}/jenkins.xml -o ${args}"
  }
}

The above example shows the script being passed in to one static method, invoked from a Scripted Pipeline as follows:

@Library('utils') import static org.foo.Utilities.*
node {
  mvn this, 'clean package'
}

For more info see jenkins shared library documentation: https://jenkins.io/doc/book/pipeline/shared-libraries/

grolegor
  • 1,260
  • 1
  • 16
  • 22
0

Try adding propagate and wait like below:

build job: 'Job Name', parameters: [ string(name: 'ENVIRONMENT', value: 'sit'), string(name: 'param1', value: 'value1' ) ],propagate: true, wait: true
Nicola Ben
  • 10,615
  • 8
  • 41
  • 65
0

Ok. So I figured out the problem.

One of the shared file name was build.groovy which was causing conflicts with build pipeline step. Renamed the file and that fixed the issue.

Avadh
  • 51
  • 1
  • 3
  • 10