I need to be able to create simple HTTP POST request during our Jenkins Pipeline builds. However I cannot use a simple curl sh script as I need it to work on Windows and Linux nodes, and I don't wish to enforce more tooling installs on nodes if I can avoid it.
The Groovy library in use in the Pipeline plugin we're using should be perfect for this task. There is an extension available for Groovy to perform simple POSTs called http-builder, but I can't for the life of me work out how to make use of it in Jenkins' Groovy installation.
If I try to use Grapes Grab to use it within a Pipeline script I get an error failing to do so, as seen here.
@Grapes(
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
)
Maybe Grapes Grab isn't supported in the bundled version of Groovy Jenkins uses. Is it possible to simply download and add http-builder and its dependencies to the Jenkins Groovy installation that goes out to the nodes?
For the Jenkin's Pipeline I would recommend installing the "HTTP-Request" plugin
It is nicely integrated in groovy so you can use it like this:
You have to download and copy the ivy.jar into the Jenkins lib directory (e.g. C:\Program Files (x86)\Jenkins\war\WEB-INF\lib) and restarting Jenkins (e.g. through system services), it's then possible to use @Grab from the Script Console. Further reading: https://groups.google.com/forum/#!msg/job-dsl-plugin/EG6eqQYYI7M/2TKKysNw4QEJ
Perhaps I'm missing something, but why not just use standard java libraries that are already on the jenkins classpath?