2

我试图将非共享库类导入共享库类并收到错误:

文件结构

.
├── src
│   └── org
│       └── jenkins
│            └──shared_library.groovy
│            └──not_shared_library.groovy
│
│── jenkinsfile.groovy

not_shared_library 类

package src.org.jenkins 

class not_shared_library {
private name

not_shared_library(name) {
 this.name = name
}

def some_func(){
  return this.name+"is not_shared_library_obj"
}

shared_library 类

package src.org.jenkins
import  src.org.jenkins.not_shared_library 

class shared_library implements Serializable {
private steps

shared_library(steps) {
    this.steps = steps
}
def not_shared_lib = new not_shared_library("not_shared_lib")

def get_not_shared_library(){
     print not_shared_lib.some_func()
}

詹金斯文件

@Library 'shared_library'
import org.jenkins.shared_library

my_shared_library = new shared_library(steps)

node(){
  stage('my_first_stage'){
    my_shared_library.get_not_shared_library()
}

/jenkins_data/jobs/main_DEV/builds/51/libs/global_utils/src/org/jenkins/shared_library.groovy:8:无法解析类 src.org.jenkins.not_shared_library @ 第 8 行,第 1 列。导入 src.org。 jenkins.not_shared_library @ 第 116 行,第 21 列。 not_shared_lib = new not_shared_library("not_shared_lib") ^

4

0 回答 0