Recently I tried to add Shared Libraries to my Jenkins instance to make it easier to maintain all code that runs in each project.
- I have a repo
myorg/jenkins
Inside of it I have Jenkinsfile and groovy file meant to contain libraries, Jenkinsfile looks like this:
@Library('utils@develop')_
import com.*
jenkinsSlave = "slave.myorg.com"
node(jenkinsSlave) {
stage('Test') {
def var = "kek"
myorg.echoTest(var)
}
}
I try to execute echoTest
method there and I'm passing one argument.
Shared libs look like this (Jenkinsfile is in root directory of this repo):
src
└── com
└── myorg
└── Utils.groovy
Utils.groovy:
#!/usr/bin/groovy
package com.myorg
def echoTest(test) {
println("Test + ${test}")
}
return this
In Jenkins I've added this repo to global libraries section and I pointed to main branch, which is develop in this case.
Unfortuantely, when I run build jenkins throws this:
groovy.lang.MissingPropertyException: No such property: myorg for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:264)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
at org.kohsuke.groovy.sandbox.impl.Checker.checke
[...]
I tried various configuration but so far I cannot make this work. I've tried to follow few tutorials about implementing this and I cannot pass through here.
Does someone notice any misconfiguration in this setup?