I have created a shared library to hold my declarative pipeline and then calling it in Jenkinsfile. In Jenkins file there are definitions for for methods that are invoked in the pipeline scripts in the shared library. I don't understand why this error occur. What is a solution for this?
Jenkinsfile:
@Library('jenkinsLib')_
def getVar(){
echo "${env.myVar}"
}
mymaster()
Under var in jenkinsLib shared library a script mymaster.groovy:
def call(){
pipeline {
agent any
stages {
stage('one') {
steps {
echo "This is Pipeline one"
getVar()
}
}
}
}
}
It can work when the functions are defined with the pipeline definition which opposes DRY and make pipelines look big and repeated. Below shows this case:
def call(){
pipeline {
agent any
stages {
stage('one') {
steps {
echo "This is Pipeline one"
getVar()
}
}
}
}
}
def getVar(){
echo "${env.myVar}"
}