Issue
How can I add/edit new code to my Jenkins instance that would be accesible in a DSL script? Context follows
I've inherited a Jenkins instance. Part of this inheritance includes spending the night in a haunted house writing some new automation href="https://wiki.jenkins.io/display/JENKINS/Groovy+plugin" rel="nofollow noreferrer">in groovy via the Jobs DSL plugin. Since I'm fearful of ruining our jenkins instance, my first step is setting up a local development instance.
I'm having trouble running one of our existing DSL Scripts on my local development instance -- my builds on the local server fail with the following in the Jenkins error console.
Processing DSL script jobs.groovy
ERROR: startup failed:
jobs.groovy: 1: unable to resolve class thecompanysname.jenkins.extensions
The script in question starts off like this.
import thecompanysname.jenkins.extensions
use(extensions) {
def org = 'project-name'
def project = 'test-jenkins-repo'
def _email = '[email protected]'
So, as near I can tell, it seems like a predecesor has written some custom Groovy code that they're importing
import thecompanysname.jenkins.extensions
What's not clear to me is
- Where this code lives
- How I can find it in our real Jenkins instance
- How I can add to to my local instance
Specific answers are welcome, as our here's how you can learn to fish answers.
Solution
While there may be other ways to accomplish this, after a bit of poking around I discovered
The Jenkins instance I've installed has an older version of the Jobs DSL plugin installed.
This version of the Jobs DSL plugin allowed you to set an additional
classpath
in your Process DSL Builds job section that pointed to additionaljar
files.These jar files can give you access to additional classes in your groovy scripts (i.e.
thecompanysname.jenkins.extensions
)
Unfortunately, more recent versions of the Jobs DSL plugin have removed this option, and it's not clear if it's possible to add it back. That, however, is another question.
Answered By - Alan Storm
Answer Checked By - Terry (JavaFixing Volunteer)