简体   繁体   中英

Extending the Jenkins Groovy DSL

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 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 = 'foo@example.com'

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

  1. Where this code lives
  2. How I can find it in our real Jenkins instance
  3. How I can add to to my local instance

Specific answers are welcome, as our here's how you can learn to fish answers.

While there may be other ways to accomplish this, after a bit of poking around I discovered

  1. The Jenkins instance I've installed has an older version of the Jobs DSL plugin installed.

  2. This version of the Jobs DSL plugin allowed you to set an additional classpath in your Process DSL Builds job section that pointed to additional jar files.

  3. These jar files can give you access to additional classes in your groovy scripts (ie 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.

Configure Global Security -> uncheck "Enable script security for Job DSL scripts".
works for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM