Issue
I'm coding Jenkins pipelines but my development process is extremely inefficient. For each modification, I must commit and push my code, and manually run the pipeline. A simple typo makes me do it all again. My version control log is a mess.
I'm trying to use the Pipeline Linter, but it fails since it doesn't recognize the Shared Libraries that I'm using.
Here is a simplified version of my code that I'll try to lint. This code works when I run it from the interface:
//importing class MyClass defined in src/com/company/MyClass.groovy
import com.company.MyClass.*
//importing src/com/company/helper/Log.groovy
import com.company.helper.Log;
def call(String env) {
def mud
pipeline {
agent none
stages{
stage('Checkout') {
agent any
steps {
mud = new MyClass(script: this)
}
}
}
}
}
I run the pipeline linter with this command:
ssh -p 8222 jenkins declarative-linter < myPipeline.groovy
And, although it works fine when I run the pipeline in Jenkins, I get the following lint validation error:
Errors encountered validating Jenkinsfile:
WorkflowScript: 2: unable to resolve class com.company.helper.Log
@ line 2, column 1.
import com.company.helper.Log;
^
WorkflowScript: 25: unable to resolve class MyClass
@ line 25, column 35.
mud = new MyClass(script: this)
How do I use the pipeline linter with shared libraries?
I also welcome any help to streamline my development process!
Solution
Answer is that it isn't possible to check and Jenkins pipeline developers are doomed to have a very inefficient development process.
I've just found that there is an issue about this in Jenkins bug database. I've tried some of the solutions, but nothing worked.
I'd still like any tips about how to efficiently code Jenkins pipelines.
Answered By - neves
Answer Checked By - Terry (JavaFixing Volunteer)