I'm unable to use libraryResource
to load a resource using Jenkins.
I've found plenty of example of people using libraryResource
to load resources but no one that has the specific errors i'm getting so i assume that i'm missing something but i've no idea what that might be.
I'm trying to load a python script that will be reused by almost all jobs.
I've placed a simple test script in resouces/org/foo/test.py
which as far as i understand i should be able to read using:
libraryResource('org/foo/test.py')
But i get the error:
hudson.AbortException: No such library resource org/foo/test.py could be found.
I use a pipeline script that is loaded from SCM that is configured in the projects configuration in jenkins. This is the structure of the git repository from which the pipeline script is loaded.
-src
-org
-shared
+Utilities.groovy
-jobs
-nighly
+nightly.groovy
-resources
-org
-foo
+test.py
Loading the Utitilies.groovy
using shared library at the root of nightly.groovy
@Library('shared-utilities')
import org.shared.Utilities
What I've tried:
libraryResource
outside of stages, in stages and on nodesscm
before running libraryResource
foo/test.py
, resources/org/foo/test.py
Based on the output from checkout scm the latest commit containing resources/org/foo/test.py
is being fetched and it's there on the job root on the agent.
I'm out of ideas and I appreciate any help/suggestion that you have. I really would like to avoid having to commit this script to all projects that use it since its only used by Jenkins.
A shared library in Jenkins is a collection of Groovy scripts shared between different Jenkins jobs. To run the scripts, they are pulled into a Jenkinsfile. Each shared library requires users to define a name and a method of retrieving source code.
Create a separate git repo for the Jenkins pipeline library & push the shared library code to that repo. Integrate the shared library repo in Jenkins under the Manage Jenkins section. Create Jenkinsfile in the project. In that Jenkinsfile, Import & use the shared library.
If the shared library is loaded from SCM and your workspace path is jenkins/workspaces/jobName , then a copy is checked out to jenkins/workspaces/jobName@libs or similar (might be suffixed with a number if that path is occupied by another concurrent build).
JSL is usually a semantically versioned gradle groovy project kept in a git repository which is git cloned by Jenkins and put on a classpath when a pipeline job using a Jenkinsfile request for it.
What you're missing is the context/scenario under which usage of libraryResource
API becomes applicabLe.
libraryResource
: Load a resource file from a shared library Reads a resource from a shared library and returns its content as a plain string.
So if you had provisioned a shared library, then you may use libraryResource
inside your shared library to read a resource in located in resource
directory of the same shared library.
Hope that clears things up better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With