update dsl job

76 views
Skip to first unread message

Jozsef Sin

unread,
Oct 27, 2015, 12:07:19 PM10/27/15
to job-dsl-plugin
Hi!

Does anybody knows how to update a dsl job?
I`d like to add new conditional step to an already created dsl job.

Thanks

Victor Martinez

unread,
Oct 27, 2015, 2:44:49 PM10/27/15
to job-dsl-plugin
Hi,

Why do you need to update an existing DSL job? If you already coded your jobs with DSL then you can edit them again to include your changes and run the seed job.

Bear in mind, you can configure the process job DSL build action to overwrite any existing jobs. Default action is doing nothing.

IMO if you do the above suggestions then you cans "update" any DSL jobs

I hope it helps

Cheers

Jozsef Sin

unread,
Oct 28, 2015, 10:35:38 AM10/28/15
to job-dsl-plugin
Hi,

For instance I add a new slave node to my jenkins and I`d like to update the already created dsl job (created with seed job) with a new conditional step refers to the new node.
The seed job writes the job creation time in the job description field which indicates a new package build date
but every time I add a new slave node and rerun the seed job (with  overwrite any existing jobs ) the original description get lost.

Thanks for the answer

Victor Martinez

unread,
Oct 28, 2015, 6:42:40 PM10/28/15
to job-dsl-plugin
If I understood correctly, you need to configure your job only when a new slave node has been added? If that's the case you can use the JobDSL to drive that only if you hack the dsl a bit and include your slave creation as part of the DSL script (that's an idea)

JobDSL uses internal JenkinsAPI and you can configure and create new slaves at the beginning of your script then you can add the conditional step:


import jenkins.model.*
import hudson.model.*
import hudson.slaves.*

slaves
= ["slave1", "slave2", "slave3" ]
slaves
.each {
   
if (! jenkins.instance.getNode(it)) {
      jenkins
.instance.addNode(new DumbSlave(it,
                                             "Dummy slave, only generated once and you can edit it afterwards via WebUI",
                                             "/home/jenkins/",
                                             "1",
                                             
Node.Mode.NORMAL,
                                             
"test-slave-label",
                                             new JNLPLauncher(),
                                              new RetentionStrategy.Always(),
                                              new LinkedList()))
   
} else {
       println
"It was already created"
   
}
}


job('example-1') {
    steps
{
        slaves
.each { slave ->
          conditionalSteps
{
            condition
{
                stringsMatch
('${SOME_PARAMETER}', "${slave}", false)
           
}
            runner
('Fail')
            steps
{
                shell
("echo 'just one step'")
           
}
         
}
       
}
   
}
}


I've used the below example:

Docs:

Bear in mind I haven't tested and might not work, but you get the idea that you can run something like that in case you need...

I hope it helps

Cheers
Reply all
Reply to author
Forward
0 new messages