如何在Jenkins共享库中使用第三方库?
我想在Jenkins SharedLibraries中使用第三方库(HTTPBuilder)。但会出现错误。 第三方库缓存在我的Jenkins master上的~/.groovy/grapes/中 HttpRequest.goorvy如何在Jenkins共享库中使用第三方库?,jenkins,Jenkins,我想在Jenkins SharedLibraries中使用第三方库(HTTPBuilder)。但会出现错误。 第三方库缓存在我的Jenkins master上的~/.groovy/grapes/中 HttpRequest.goorvy @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1') import groovyx.net.http.HTTPBuilder
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.Method.POST
import static groovyx.net.http.ContentType.JSON
import groovyx.net.http.ContentType
def http = new HTTPBuilder('http://192.168.100.10:9100')
def userExist
@NonCPS
public int searchUser(String userLogin) {
http.request(GET, JSON) { req ->
uri.path = '/sonarqube/api/users/search'
headers.'User-Agent' = 'curl/7.60.0'
headers.'Authorization' = "Basic $userPassBase64"
headers.Accept = 'application/json'
uri.query = [q: userLogin]
response.success = { resp, reader ->
assert resp.statusLine.statusCode == 200
userExist = reader.paging.total
return userExist
}
}
}
詹金斯管道
@Library('SharedLibraries') _
import com.test.jenkins.HttpRequest
AddUserSonarProject user = new AddUserSonarProject()
pipeline {
agent { any }
environment {
userLogin = 'cycwll'
}
stages {
stage('Pull Source code') {
steps {
script{
user.searchUser(userLogin)
}
}
}
}
在Jenkins控制台输出中
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@25d9b671
**Caused: java.io.NotSerializableException: groovyx.net.http.HTTPBuilder**
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:926)
解决方案:
将http声明放入方法中
public int searchUser(字符串userLogin){
def http=新的HTTPBuilder(“”)
....
}在Jenkins控制台输出中