1

In my Jenkins build, I have a Groovy script(because I am using the Pipeline plugin) where I am trying to make an API call using OkHttpClient.

I have the following Grape code that I got from here:

@Grapes(
    @Grab(group='com.squareup.okhttp', module='okhttp', version='2.7.5')
)

For this, I am getting:

General error during conversion: Error grabbing Grapes -- [unresolved dependency: com.squareup.okkhttp#okhttp;2.7.5: not found]

java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: com.squareup.okhttp#okhttp;2.7.5: not found]
at sun.reflect.NativeContructorAccessorImpl.newInstance0(Native Method)

Any idea what could be wrong?

Can't Grape retrieve packages when running in a Jenkins pipeline script?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
bsky
  • 19,326
  • 49
  • 155
  • 270

1 Answers1

0

I had a similar issue running a Jenkins Groovy console script that used the @Grab annotation. The error was caused by the Jenkins Groovy not being able to resolve my corporate proxyhost server.

The Groovy proxyserver can be set on the command line, like this:

groovy -Dhttp.proxyHost=yourproxy -Dhttp.proxyPort=portNumber yourscript.groovy

but I was not able to find out how to do that for the Jenkins Groovy.

I ended with the following workaround:

You can install the required library from the command line (assuming you have access to the Jenkins server). In that case the proxyserver is easily specified as follows:

grape -Dhttp.proxyHost=proxy.server.net -Dhttp.proxyPort=port install %groupId% %artifactId% [%version%]

Also insure that you install the library while logged in under the Jenkins user account. Grapes libraries are user account specific.