Issue
In simple form, I have 2 groovy files in the repo in /jenkins subfolder. File A.groovy and B.groovy. Inside A.groovy I have a load line
load(env.WORKSPACE + "@script/jenkins/B.groovy")
java.nio.file.NoSuchFileException:
/Users/user/.jenkins/workspace/JobName@script/jenkins/B.groovy
But as we see, overall looks like load function created kinda almost correct url. The point is my actual fetched repo, and particularly A.groovy is getting into the additional subfolder. I see that in the very beginning of the logs and can find locally there.
Checking out git ... into /Users/user/.jenkins/workspace/JobName@script/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e/jenkins/A.groovy
Tried to log whole env
object using echo sh(script: 'env|sort', returnStdout: true)
and there is no any property containing that subfolder name at all.
Why I am getting that extra ecb7a9317b1ad672693830224d9e0ce2b9b3f730c043bb85f48925f3cdcab65e subfolder and how can I either get rid of it or get it's name somehow to compose correct url for import?
Solution
I've found a workaround (by searching the folder), but would like to find a better and native way.
Where jenkins
in -name 'jenkins'
is the subfolder name containing groovy scripts.
git_jenkins_folder = sh (
script: "find \"" + WORKSPACE + "\"@script -type d -name 'jenkins'",
returnStdout: true
).trim()
utils = load("$git_jenkins_folder/Utils.groovy")
Which generates the correct working path like this.
/Users/user/.jenkins/workspace/JobName@script/ecb7a9317b1ad672698830264d9e0ce2b9b6f330c043bb85f48623f3cdcab65e/jenkins
Answered By - bodich
Answer Checked By - Candace Johnson (JavaFixing Volunteer)