简体   繁体   English

在 Jenkins 管道中使用共享库时,我是否必须在共享库中使用“call{}”?

[英]Do i have to use "call{}" in a shared library when using it in a Jenkins pipeline?

I'm working on transforming a whole Jenkins from normal jobs to DSL/Pipelines.我正在努力将整个 Jenkins 从正常工作转换为 DSL/管道。 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?我如何、在哪里以及不能使用 call() 来实际“调用”它们?

If you want to invoke the bar method in the Foo class you could do any of these:如果您想在Foo class 中调用bar方法,您可以执行以下任何操作:

Option 1:选项1:

common.Foo.bar('some argument')

Option 2:选项 2:

import common.*

Foo.bar('some argument')

Option 3:选项 3:

import static common.Foo.*

bar('some argument')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM