Jenkins shared library include java jar file - jenkins

In my Jenkins shared library how can I import java jar class file. I have helper function written in Java and have it as jar fie. How can I include this jar file part of my Jenkins shared library?
Included jar file in resources Directory but pipeline script not finding the class file. giving unable to resolve class error message.
Thanks
SR

This is the Generic way of referring a Jenkins shared library.
// Jenkinsfile
#Library('first-shared-lib')

You may try using libraryResource step in your pipeline script as:
libraryResource './resource/abc.jar'

Related

Load groovy files into jenkins and invoke the files just like invoking shared library files

I have multiple groovy files which are wrote as a library files and one file is invoked in another file using file name.
To avoid git dependency we are trying to load pipeline shared library from local repository.
I want to load all groovy files into jenkins runtime and invoke it using file name.
Can someone please help me on this?

How to access a file from different folder in a Jenkins shared library?

I have a shared library with the folder structure like this:
vars/all groovy functions.
Test/a java file that does something.
I'm trying to run this file with the command 'java nameOfFile' in a groovy function inside the folder vars.
How can I do that?

Jenkins PipelineShared library using Java

I know using Groovy, Jenkins Pipeline Shared library can be developed.
I want to know if there is any way the same Jenkins pipeline shared library can be developed using Java or any other technology?
You build groovy shared library and import your Java library by using Grab.
See example how to import yaml library:
#Grab(group = 'org.yaml', module='snakeyaml', version = "1.18")
import org.yaml.snakeyaml.Yaml
Be sure that library jar file in Jenkins classpath.
Works for me with Jenkins 2.150.1

jenkins use shared library in non default location

Following
https://jenkins.io/blog/2017/02/15/declarative-notifications/
I use in my java project a shared library vars/sendNotification.groovy that is used in a jenkins pipeline in src/main/resources/pipeline.
I got this folder structure from
https://jenkins.io/doc/book/pipeline/shared-libraries/
Is it somehow possible to put the groovy script in src/main/resources/ as well? On jenkins -> configuration -> Global Pipeline Libraries it doesn't give me options to specify a path of the shared library (the groovy script)
Thanks!

How to install gradle-grails-plugin?

Complete gradle nooby here.
I want to be able to execute grails build commands like "grails compile", "grails test-app" and so forth from gradle.
I found the grails-gradle-plugin from Peter Ledbrook at: https://github.com/grails/grails-gradle-plugin.
Cloning the repository I get some files and folders. In the readme file it says " include the required JARs via buildscript {} and 'apply' the plugin". The apply part sure I get but how do I add the JAR? And which jar? Do I need to use gradle on the build file in the folder of the downloaded plug-in and compile a jar? And ones I get the jar where do I place it and how do I include it in my projects build.gradle file?
I have a feeling this is going to be ridiculously easy but I just can't get it to work.
In Gradle, the jars are added to build script or to your application class path through dependencies closure e.g.
dependencies {
compile "org.grails:grails-crud:1.3.4"
compile "org.grails:grails-gorm:1.3.4"
compile "ch.qos.logback:logback-core:1.0.7"
compile "org.slf4j:slf4j-api:1.7.2"
}
compile is a name of one of the many configurations (there are also test, runtime etc.) and e.g. "org.grails:grails-crud:1.3.4" is a reference to a jar in one of the public repositories, which are also specified in your scripts in repositories closure.
You can read more about Gradle dependency management in http://gradle.org/docs/current/userguide/dependency_management.html.
For your Grails project you need to define a build.gradle file which looks similar to what is described in the README.
Though I tried today to just create a simple Grails project using that plugin and gradle init command and it didn't work. I have created an issue for that: https://github.com/grails/grails-gradle-plugin/issues/16.

Resources