Import library into Jenkins groovy script - jenkins

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?

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.

Related

How to use Rhapsody from Jenkins to generate code - Facing License issue

I am trying to generate code from RhapsodyCL using a batch script. When I run this batch script using cmd, the code is generated just fine but when I try to generate code via Jenkins I am getting error in the Jenkins build output which I think is because of trying to start RhapsodyCL due to 'license not found'.
The error in Jenkins console output looks like:
11:33:10 C:\Test>rhapsodyCL.exe -f C:\Test1\Test-BitBucket\script.bat
11:33:13
11:33:13 C:\Test>exit -1
-1 is the rhapsody return code for license not found.
So is this a Jenkins issue that it can not find the Rhapsody license ? Or is it something else ?
There are not many details in your question but rhapsody code generation via jenkins has worked for me in the past so:
Is it rhapsody installed for All Users in the jenkins machine?

Where is 'Pipeline: Model definition' on Jenkins 2.89.3

I am getting this 'No such DSL method 'pipeline' found among steps' from Jenkins. From a quick google search, it seems like I am missing the Pipeline: Model definition plugin. However, I can't find the plugin on in 'Plugin Manager'. I have tried to install 'Pipeline: Model API', and a few other plugins with no luck resolving the issue.
How can i install 'Pipeline: Model definition' on jenkins 2.89.3?
Installing 'Pipeline: Model definition' resolve the issue

Jenkins deploying artifact to WebLogic

Trying to deploy an artifact using Jenkins WebLogic Deployer Plugin.
Getting following error:
Error: Could not find or load main class weblogic.Deployer
According to the documentation I should be using wlthint3client.jar (WebLogic version 12.1.3) but this client jar doesn't contain above class (Deployer), tried using the wlfullclient.jar which is said to be deprecated but if that throws another exception:
Hi, I want to install a war file generated from Jenkins to WebLogic, both on different machines, but when the installation runs an error is generated:
java.lang.NoClassDefFoundError: weblogic/deploy/api/spi/DeploymentOptions
at weblogic.deploy.api.tools.deployer.Jsr88Operation.init(Jsr88Operation.java:70)
Any ideas what could be the issue?
Regards!
I am having the same problem. I solved it actually adding all of these three libraries to the Additional Classpath:
wlthint3client.jar:weblogic.jar:wlfullclient.jar

Howto set up classpath for System Groovy Script in Jenkins

Documentation for the Groovy Plugin of Jenkins states that
The system groovy script, OTOH, runs inside the Jenkins master's JVM.
Thus it will have access to all the internal objects of Jenkins, so
you can use this to alter the state of Jenkins. It is similar to the
Jenkins Script Console functionality.
Yet I find that I have a groovy script that I can successfully run in Jenkins Script Console but which does NOT run if entered as a "System Groovy Script" on a build configuration. There are compiler errors. Clearly, the Jenkins Script Console is running with a different classpath than the script in my build. But I can't find information on what the default classpath is when running a script for a build or what the classpath is when running from the Script Console, so I might duplicate that for my script.
Also, the plugin offers a classpath entry field for running the script as a file but that option does not exist for entering the script as text.
I can't get my script to work either way.
What am I missing?
I think the answer is that the Script Console auto-imports the whole Jenkins library. That is not the case with the System Groovy Script. So what worked for me was to run the script, and for every compiler error about an unknown class, add an import statement for that class. I learned what packages they were from by looking at Javadocs.
Automating this would be a nice improvement to the plugin.
May be use the grab dependency management to resolve the library to add

Maven plugin failed after upgrading Jenkins to 1.505

I have upgraded my Jenkins server to 1.505 but unexpectedly building with Maven plugin is not working and it throws an exception in the Jenkins logs
Error injecting constructor, java.lang.NoClassDefFoundError: hudson/ivy/AntIvyBuildWrapper
and after an hour googling this issue I found that Maven plugin guys upgrade their code base and it failed on an "optional" dependency, so I added the "optional plugin" but still it fails silently without any exception in the Jenkins logs.
the error appears on the console log is ERROR: Couldn't find Maven executable.
any hints ?!
The new maven plugin adds a new option to the Jobs I have (under the build section -> Invoke Maven 3 there is a new field called Maven version).
So what we need to do is open each job configuration page and hit the save button in order to save the default value and it will solve the problem.

Resources