Trigger Jenkins Job from shared library

jenkins shared library
sonarqube jenkins shared library
jenkins shared library freestyle job
jenkins declarative pipeline shared library example
creating a shared library jenkins
jenkins pipeline in shared library
jenkins shared library docker
jenkins plugin shared library

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?


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

Trigger another job from the shared library · Issue #416 · SAP , This is more of a feature request. I would like to see a library which triggers another jenkins job with provided parameters. The triggering happens from a shared library we use with the workflow-cps-global-lib plugin. Any ideas would be highly appreciated, so far we are absolutely clueless. I will update this issue once we find out more.


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.

Jenkins: How to use shared libraries for configuration, You need a trigger that is fired upon commits to the shared library. of Jenkins is that it triggers the build on changes on shared library, unless  The Shared Library functionality within Jenkins allows you to consolidate the code you use within one repository to be shared across your jobs. Configure seed.groovy to create a Pipeline Job (deployment job) and Multibranch Pipeline Job (test job) per service.


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/

Jenkins trigger build if shared library changes, I have Jenkins Pipeline job define in my git repo as. // File: deployment/​jenkinsfiles/staging/Merge @Library("my_shared_lib") _ import  Jenkins; JENKINS-55163; Not able to Trigger Jenkins Job from shared library file. Log In. Export. XML; Word ; Printable; Details. Type: Bug Status: Resolved (View Workflow) Priority: Critical . Resolution: Not A Defect Component/s: pipeline-build-step-plu


Setting up a shared library and seed job in Jenkins - Part 2, Finally we will need to trigger the building of the specific poc-micro_deploy and poc-micro_test jobs we are onboarding. Hard code the repo  Automatic Workflow (job) creation in Jenkins per new branch in the repo Build specific to that child-branch and its unique scm change and build history. Automatic job pruning/deletion for branches deleted from the repository, according to the settings.


Setting up a shared library and seed job in Jenkins - Part 1, Setting up a shared library and seed job in Jenkins - Part 1 we are ready to trigger our seedJob to create a Freestyle job with jobName . For Shared Libraries which only define Global Variables (vars/), or a Jenkinsfile which only needs a Global Variable, the annotation pattern @Library('my-shared-library') _ may be useful for keeping code concise. In essence, instead of annotating an unnecessary import statement, the symbol _ is annotated.


Pipeline: Shared Groovy Libraries, Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software. This method also means that the shared Jenkins library scripts in Groovy are stored in another Git repository (e.g., “shared-lib” on Github) and only git push to the workflowLibs.git repository in the event of deployment. Having the shared scripts in Git allows you to track changes, perform tested deployments, and reuse the same shared library across a large number of instances.