如何在Jenkins共享库

时间:2018-06-13 06:48:33

标签: jenkins jenkins-pipeline jenkins-shared-libraries

我试图将一个不共享的库类导入共享库类并收到错误:

文件结构

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

not_shared_library calss

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 calss

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()
}

jenkinsfile

@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列.import src.org.jenkins.not_shared_library @第116行,第21列.not_shared_lib     = new not_shared_library(“not_shared_lib”)^

0 个答案:

没有答案