user1888955
user1888955

Reputation: 626

How to add a jar for Groovy plugin in Jenkins?

I need to use some classes in httpclient.jar when building a project in Jenkins. I added this jar to both {Groovy_Classpath}\lib and {Jenkins_Path}\plugins\groovy\WEB-INF\lib and tried to imported into my job (also see the screenshot below):

import jenkins.model.*
import hudson.model.*
import groovy.*
import org.apache.http.*

HttpClient httpClient = HttpClientBuilder.create().build();

enter image description here

It has two issues:

startup failed: 
Script1.groovy: 6: unable to resolve class HttpClient 
@ line 6, column 12. 
   HttpClient httpClient = HttpClientBuilder.create().build(); 
              ^ 
1 error

So I removed HttpClient and saw another:

Caught: groovy.lang.MissingPropertyException: No such property: HttpClientBuilder for class: xxxx
groovy.lang.MissingPropertyException: No such property: HttpClientBuilder 

I guess probably they meant the same thing - the class couldn't be found. But I have no idea how to resolve as I've added the jar to classpath...

Updated on the basis of Mike W's suggesion enter image description here

Upvotes: 1

Views: 2819

Answers (1)

Mike W
Mike W

Reputation: 3932

Try getting the dependency using Grape, add the following to the top of your script.

@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.5.3'))

Upvotes: 1

Related Questions