znhv
(znhv)
November 17, 2022, 2:49pm
1
There is such a structure:
+- src
| +- org
| +- foo
| +- bar.groovy # different classes
+- vars
| +- foo.groovy # declarative pipelines
| +- baz.groovy # initializing pipelines
foo.groovy :
#!/usr/bin/env groovy
library retriever: modernSCM([$class: 'GitSCMSource', remote: 'https://linkmygit.com/lib.git']),
identifier: 'my-lib, changelog: false
import org.foo.*
def test = new Hello()
test.msg()
Bar.groovy :
package org.foo
class Hello {
def test() {
println("Hello World!")
}
}
The library is downloaded, but the class can’t be called, it says it’s not found. I know this implementation is not suitable for a dynamic library, but I haven’t found any other options. I can’t use @Library (‘my lib’) because the library is in another repository.
Please tell me what other options are available?
halkeye
(Gavin Mogan)
November 17, 2022, 3:58pm
2
do you wan to use the groovy @grab annotation to grab an external jar file?
znhv:
library retriever: modernSCM([$class: 'GitSCMSource', remote: 'https://linkmygit.com/lib.git']),
identifier: 'my-lib, changelog: false
why do you need to pull in stuff if its part of the structure already?
znhv
(znhv)
November 17, 2022, 4:21pm
3
That’s not so. I am using pipeline script from scm. That is, I load the script from another jenkins space, so I need to load the library.
halkeye
(Gavin Mogan)
November 17, 2022, 4:37pm
4
are you having a library in one pipeline trying to load a library from another pipeline?
I think you should move it all to an external shared pipeline that both use. I don’t think you can do it this way.
znhv
(znhv)
November 18, 2022, 6:30am
5
Not quite. We have a library that lies in some kind of repository and there are several projects in jenkins. There we create a job, where we indicate that we connect to our repository and take the necessary pipeline from vars. Ideally, we don’t want to store the pipeline in the project repository, but keep everything in one place.
halkeye
(Gavin Mogan)
November 19, 2022, 12:01am
6
So I’ll admit I’m not entirely sure what you are trying to do.
If i do understand you correctly, I still think shared pipelines is the way to go, instead of trying to load things from alternative locations.
For example, for my helm charts, my pipeline is just buildHelmChart() which maps to jenkins-shared-library/buildHelmChart.groovy at f2b30f61541b21f345b4677e29bba647e1e63da7 · halkeye/jenkins-shared-library · GitHub