bal*_*omi 6 groovy class shared-libraries jenkins jenkins-pipeline
我有一个 Jenkins 文件,我正在尝试从我的共享库中实例化一个 groovy 类。我得到“无法解决类测试”
我在共享库中有一个 src/com/org/foo.groovy 文件:
package com.org
class Test implements Serializable{
String val
Test(val) {
this.val = val
}
}
Run Code Online (Sandbox Code Playgroud)
我试图在我的 jenkinsfile 中实例化它
@Library('Shared-Library@master')
import com.org //also tried to use with .foo with no success
def t = new Test("a") //doesnt work
def t = new foo.Test("a")//doesnt work
def t = new com.org.foo.Test("a")//doesnt work
Run Code Online (Sandbox Code Playgroud)
如果我将文件称为类(我无权访问其构造函数),那么有效的是什么。那是:
@Library('Shared-Library@master')
def t = new foo.com.org.foo()
Run Code Online (Sandbox Code Playgroud)
这很好,让我可以使用 foo 函数。但是,我失去了赋予类常量并使用参数构造它的能力。
知道如何定义和使用共享库中的类吗?谢谢
小智 0
@Library('Shared-Library@master')
import com.org.*;
stages{
stage('Demo') {
steps{
script{
def t = new Test("a") //this should work
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3033 次 |
最近记录: |