0
我正在尝试使用HTTP Builder在管道脚本中创建POST请求(确实在共享库中它通过命令行工作),但需要它在Jenkins中工作如何在Jenkins中使用HTTP构建器
在Jenkins中运行时出现以下错误。
No suitable ClassLoader found for grab
我的脚本如下所示
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
import static groovyx.net.http.ContentType.JSON
import static groovyx.net.http.Method.POST
import groovyx.net.http.HTTPBuilder
def gitUpdateStatus() {
String targetUrl = 'https://api.github.com/repos/myOrg/'
def http = new HTTPBuilder(targetUrl)
http.request(POST) {
uri.path = "myRepo/statuses/commit_id_here"
requestContentType = JSON
body = [state: 'failure', description: 'Jenkins Unit Tests', target_url: 'http://test.co.uk', context: 'unit tests']
headers.'Authorization' = "token 123"
headers.'User-Agent' = 'Jenkins Status Update'
headers.Accept = 'application/json'
response.success = { resp, json ->
println "GitHub updated successfully! ${resp.status}"
}
response.failure = { resp, json ->
println "GitHub update Failure! ${resp.status} " + json.message
}
}
node {
stage('Echo Client JS')
git branch: 'master', credentialsId: '${JENKINS_CREDENTIALS_ID}', url: '[email protected]:myOrg/myRepo.git'
gitUpdateStatus()
}
我看过很多帖子,其中同样的问题已经出现,但我似乎无法弄清楚如何这已经固定,任何人都可以帮助吗?
谢谢
感谢您的回答,我已经把它放到了一个共享库中,但是当调用方法时,Git不会被更新,并且这个函数会默默地失败,这就是为什么我想直接在pipline中尝试它。关于如何调试这个的任何提示请 – Richlewis
@Richlewis你可以使用[JenkinsPipelineUnit](https://github.com/jenkinsci/JenkinsPipelineUnit)进行调试。 –