[英]How to Reference A Jenkins Global Shared Library
After reviewing the docs , a number of questions here on SO, and trying a dozen or so different script configurations, I cannot figure out how to reference a shared Groovy library. 在审查了文档 ,关于SO的许多问题并尝试了十几种不同的脚本配置之后,我不知道如何引用共享的Groovy库。 I've added the library like so:
我像这样添加了库:
This appears to be working. 这似乎正在工作。 I'm referencing the script like so:
我像这样引用脚本:
You can see the error message therein: 您可以在其中看到错误消息:
Script1: 1: unable to resolve class Library , unable to find class for annotation @ line 1, column 1. @Library('sonarQubeAPI')_
脚本1:1:无法解析类库,无法找到用于注解的类@第1行,第1列。@Library('sonarQubeAPI')_
The script code, not I think it matters, looks like this: 脚本代码(我认为并不重要)如下所示:
import groovy.json.JsonSlurper
class SonarQubeAPI{
static string getVersion(){
return "1.0";
}
static void getSonarStatus(projectKey){
def sonarQubeUserToken = "USERTOKEN";
def projectStatusUrl = "pathtosonarqube/api/qualitygates/project_status?projectKey=" + projectKey;
println("Retrieving project status for " + projectKey);
def json = getJson(sonarQubeUserToken, projectStatusUrl);
def jsonSlurper = new JsonSlurper();
def object = jsonSlurper.parseText(json);
println(object.projectStatus.status);
}
static string getJson(userToken, url){
def authString = "${userToken}:".getBytes().encodeBase64().toString();
def conn = url.toURL().openConnection();
conn.setRequestProperty( "Authorization", "Basic ${authString}" );
return conn.content.text;
}
}
I'm probably just a magic character off, but I can't seem to lock it down. 我可能只是一个魔术人物,但我似乎无法将其锁定。
Shared libraries are a feature of Jenkins Pipelines, not of Jenkins (core) itself. 共享库是Jenkins Pipelines的功能,而不是Jenkins(核心)本身的功能。 You can use them only in Pipeline jobs (and child types like Multibranch Pipeline).
您只能在管道作业(和子类型(例如多分支管道))中使用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.