Issue
I have a Jenkinsfile that uses the shared Jenkins lib and calls method inside the groovy file defined below.
shared-jenkins-lib
|
|-----------vars
| |-------pipeline_script.groovy
|
|-----------scripts
|-------test_script.groovy
This is the structure of the library and pipeline_script.groovy
has a method test
which is called from jenkinsfile.
def test(){
dockerArgs = "--entrypoint /bin/bash"
dockerCommand = "`../scripts/test_script.sh`"
dockerOut = sh (script: "docker run ${dockerArgs} ${image} ${dockerCommand}", returnStatus: true)
}
I refer test_script.sh
but doesn't seem to find the file in that location.
I am running jenkins within docker. What is the correct way to refer to the script
Solution
As stated in the docs of the shared libraries plugin, a library repo has a very specific structure. The root of the repo can have the following 3 folders:
+- src # Groovy source files
| +- org
| +- foo
| +- Bar.groovy # for org.foo.Bar class
+- vars
| +- foo.groovy # for global 'foo' variable
| +- foo.txt # help for 'foo' variable
+- resources # resource files (external libraries only)
| +- org
| +- foo
| +- bar.json # static helper data for org.foo.Bar
If you want to refer to a helper code/data from your library method, you should put it in the resources
directory, and then you can retrieve it with the libraryResource
step, also described in the docs.
Answered By - YoavKlein