Home > database >  Do i have to use "call{}" in a shared library when using it in a Jenkins pipeline?
Do i have to use "call{}" in a shared library when using it in a Jenkins pipeline?

Time:12-29

I'm working on transforming a whole Jenkins from normal jobs to DSL/Pipelines. Had to implement a shared library for all the imports. In the said library there is a whole load of scripts. Currently, all of them are set up like this:

package common

class Foo {
      static String bar(String text) {  stuff  }
      static String bar2(String text) {  stuff  }
      static String bar3(String text) {  stuff  }
}

And in the pipeline:

#!/usr/bin/env groovy
@Library('jenkins-shared-libs') _
import common.*

There are many scripts and many methods. How, where, and can I not use call() to actually, "call" them?

CodePudding user response:

If you want to invoke the bar method in the Foo class you could do any of these:

Option 1:

common.Foo.bar('some argument')

Option 2:

import common.*

Foo.bar('some argument')

Option 3:

import static common.Foo.*

bar('some argument')
  • Related