How to define a FreeStyle Job first , and then populate it later on?

22 views
Skip to first unread message

tbper...@gmail.com

unread,
May 9, 2017, 6:18:52 PM5/9/17
to job-dsl-plugin


Hi folks,

I am trying to do something which seems to be very simple, however somehow I am struggling to get it right.

Let's say I have a very simple job like this:

def job1 = job("job1") {
    steps {
        cmake {
            buildToolStep {}
        }
    }
}

I want to define the previous job equivalently, first by defining a "job1" variable:

def job1 = job("job1")

And then populating it with the build steps later on. Something like:

job1 {
    steps {
        cmake {
            buildToolStep {}
        }
    }
}

Or maybe:

def jobClosure = {
    steps {
        cmake {
            buildToolStep {}
        }
    }
}

// First try:
job1 { jobClosure }

// Second try:
job1 jobCloure

// Third try:
job1.call(jobClosure)

Unfortunately, I can't access job1.configureBlocks, because configureBlocks is private.

However, neither of the previous of my tries worked. It is very important, for my purposes / use case[1], to define the job first and only assign its configureBlocks later on.

How can I do that?


- Thiago


[1]: if you want some context, see https://stackoverflow.com/questions/43858970/jenkins-groovy-dsl-using-the-ternary-operator-to-distinguish-between-freestyle . This might potentially be a http://xyproblem.info/ , that's why I am providing my stack overflow question.

tbper...@gmail.com

unread,
May 11, 2017, 4:18:02 PM5/11/17
to job-dsl-plugin
Hi folks,

For completeness and for future readers, I am posting to say I resolved this problem. See this.
Reply all
Reply to author
Forward
0 new messages