Hi i'm trying to execute a groovy script inside the system Groovy script, i'm trying to import "groovyx.net.http.HTTPBuilder", unfortunately i'm getting an error - unable to resolve class groovyx.net.http.HTTPBuilder
Is there any way to use this package ?
If there is Grape support for system groovy Jenkins scripts you might try to use dependency management with Grape.
In your case it might be:
#Grab(group='org.codehaus.groovy.modules', module='http-builder', version='0.7.1')
import org.codehaus.groovy.modules.http-builder
Dependencies are getting from Maven so Master need to have Maven binary on it's configuration.
Related
I am new to gauge testing tool .I have a maven project that consists of specs and step implementations. Mvn package phase does generate a jar file with all the required classes. However I cant figure out how i can run the gauge specs using a Main class in java, such that i can just run the jar file to run the tests. Is this possible?
Unfortunately no, Gauge binary must be installed and available to execute the specs.
As the Gauge binary is not written in java it cannot be bundled in a jar file and invoked from a Main class.
If you'd like to automatically download and use Gauge in a CI/CD environment, try something like https://github.com/maven-download-plugin/maven-download-plugin to download gauge into a convenient location as part of your mvn build itself.
More info about this here
There is a way to do this. You have to package maven and gauge inside the project directory and include them in the jar. In the main method, unzip all files, then run a shell script to export maven and gauge in the project directory to $PATH, then execute mvn gauge:execute as usual. It's a bit of a hack as it extracts everything to the directory in which the jar is located, but it works on RHEL 7 and I haven't managed to find a cleaner method.
I have a Java project that has a lot of unit tests written in Groovy.I do not have the GDK installed and it still runs.
The project uses gradle and it has "apply plugin: groovy" in the build script but I was under the impression that it would just use groovyc which is definitely not installed.
How does this work?
Thanks
Inside your build.gradle file, inside the dependencies block, you will have a line probably like:
compile 'org.codehaus.groovy:groovy-all:2.4.1'
This line pulls in the specified version of groovy, and the groovy plugin uses it to compile your groovy code
I have the Groovy and Groovy Postbuild plugins installed in Jenkins (1.554) and have it set to automatically install Groovy 2.2.1 when needed.
After having a problem with a constructor signature I dug a little deeper and round that Jenkins is actually using 1.8.9 by running this through the groovysh CLI.
groovy> import org.codehaus.groovy.runtime.InvokerHelper
groovy> println InvokerHelper.version
It appears that the groovy post build plugin is also using 1.8.9 based on the error message I get when I try to run my script.
How can I update this? I have already set the groovy plugin to use 2.2.1. Thanks!
Groovy Postbuild plugins use the groovy version included in Jenkins (1.8.9). You can't change it.
The problem is the same as the system script in Groovy Plugin.
If you need a newer version of groovy a workaround is to do your work in a build (like Groovy Plugin purpose). Write some informations in a text file. And Read it in Post build step to do what you want with jenkins context (create badge, add summary, etc.)
Note that you can access to build workspace in post build step with:
manager.build.project.getWorkspace()
Hope it helps.
I installed Groovy v2.4.3 to /usr/share/groovy and then in my jenkins post-build task I reference my script as /usr/bin/groovy myscript.groovy similar to how #passionne described.
I have a script that I quickly put up using a #Grab annotation to import a package - namely HttpBuilder. Now I would like to actually install HttpBuilder and get rid of the annotation before putting the script in production - I do not want to grab the dependency dynamically on the prod server.
How do I actually tell Grape to install the dependency once and for all? Is there even a way to do this? If not, how should I install this package before deploying?
EDIT Following the advice from tim_yates, I donwloaded all teh JARs from HttpBuilder website, and added them to the classpath. But, when I run groovy -cp dependencies/* myApp.groovy what I get is a bunch of errors like
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/path/to/dependencies/httpclient-4.0.3.jar: 1: unexpected char: 0x3 # line 1, column 3.
PK
^
What does this mean?
If you go to the Downloads page for HttpBuilder, you can follow the links in the first paragraph and download the http-builder-xxx-all.zip for the release you want...
Expand this, and it contains the jar, and the dependency jars in the dependencies folder
Then, just add them to the classpath in the usual way and get rid of the #Grab line
I try to run my first Spock Test inside Eclipse, and it does not work.
I added all the Maven dependencies and plugins in my pom.xml, but when I run my test with jUnit, there is a popup windows with this Warning message : "No jUnit tests found".
Did you already seen this kind of message ?
What config has to be done, in order to run a Spock Test inside Eclipse ?
Thanks a lot.
Its same as running Junit test cases.
Right click on the class and run as 4Junit Test runner. see below for complete configurations and running the spock test.
Running Spock Framework with Eclipse, Gradle, Groovy: Source -
Krzysztof Goralski, blog
-Install Gradle Plugin, check it here
-Install Groovy-Eclipse for Juno or Indigo from Eclipse Marketplace (or maybe Groovy/Grails Tool Suite for Eclipse)
-Install Spock Plugin From Eclipse Marketplace if you want, check it here
-Import Project to Eclipse through Gradle Import
-Add these lines to build.gradle:
apply plugin: ‘groovy’
testCompile ‘org.spockframework:spock-spring:1.0-groovy-2.3’ (for Spring)
this is quite important, version can make some conflicts
-After this *.groovy and *.gradle files will problably looks different, Syntax colour highlightning etc. Remember that you can right click on for eg. build.gradle -> Open with -> Open With Minimalist gradle Editor etc.
-Probably you will need to make additional folder for *.groovy test files
Create new *.groovy file, class
-Basic test example, extends Specification from Spock framework and needs specific Annotations when running with Spring
-Now you can run it with JUnit from Eclipse
For integration tests you can’t use #RunWith(SpringJUnit4ClassRunner.class), and Context should looks like here #ContextConfiguration(locations = [ “/restTestContext.xml” ]) , not {} braces, but [ ]
-Spock can be used for Mocks too. Something like this: Subscriber subscriber1 = Mock() , subscriber1.isActive() >> true , So, remember >> operator for mocks.
Right click on the project > Properties > Java Build Bath > Add External Jars and add spock-core-0.6-groovy-1.8.jar and check if Groovy Libraries are there in Build Path or not. If not click on Add Library and select Groovy Runtime Libraries and restart Eclipse. Now you should be able to run. If still can't Run then try creating New Configuration and change the Test runner to Junit4 and Run it...
Check if the folder your tests are in is a source folder.