I'm trying to get information from a groovy script located under vars called from a shared library Jenkins class but gets an error. some info:
Need - global configuration file. similar to Manage Jenkins -> Configure System -> Environment variables
Goal - to be able to get global values inside shared library without sending parameters from Jenkinsfile.
- My solution - I tried to use "vars/script.groovy" which works for Jenkinsfile but not inside shared library.
file structure
.
├── src
│ └── org
│ └── jenkins
│ └──shared_library.groovy
│── vars
│ └── globals.groovy
│
│── jenkinsfile.groovy
vars/globals.groovy
def my_global() {
return 'my_global_name'
}
shared_library class
package src.org.jenkins
class shared_library implements Serializable {
private steps
shared_library(steps) {
this.steps = steps
}
def some_func(){
println globals.my_global
}
jenkinsfile
@Library 'shared_library'
import org.jenkins.shared_library
my_shared_library = new shared_library(steps)
node(){
stage('my_first_stage'){
println globals.my_global
}
stage('my_second_stage'){
println shared_library.some_func()
}
}
so, I can see the value for the first print in pipeline, but for the second I get:
No such property: globals for class: src.org.jenkins.shared_library