Execute Shared Libary From FreeStyle Job

Viewed 566

I have a shared library repository that contains all of my shared functions.

Is it possible to somehow use this within a freestyle job?

What I'm trying to accomplish is to create a freestyle job that calls and executes code from the vars folder of my shared library repository.

Is this possible at all?

Freestyle jobs have a Execute Groovy Script Build Step and I wonder if it might be possible to write a groovy script that calls a function within a global shared library.

I've tried to call the function using

GroovyShell shell = new GroovyShell()
def tools = shell.parse(new File('demoFree.groovy'))
tools.call()

demoFree.groovy being the name of the file that holds the function but my Groovy knowledge is very limited so I'm probably doing something very wrong.

I know this is easily done using a pipeline project but I'm having to deal with a legacy freestyle project which for a number of reasons isn't being moved to a declarative pipeline just yet.

1 Answers

No. According to the Documentation shared libraries are meant to be executed only from Jenkins pipelines.

However, you can easily create a pipeline job, choose Pipeline Script (instead of Pipeline from SCM) and write the code you need that uses your library.

You will find it much more convenient that using a FreeStyle job.

Related