whats the best way to create Jenkins through code

60 views
Skip to first unread message

prasad gorle

unread,
Oct 13, 2017, 5:44:32 PM10/13/17
to job-dsl-plugin
whats the best way to create Jenkins through code

below script works  <jenkins-url>/script but not through process DSL

import hudson.model.*
import jenkins.model.*
import hudson.slaves.*
import hudson.plugins.sshslaves.*
import hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy





// INSERT "Launch Method" SNIPPET HERE

// Define a "Permanent Agent"
def launcher = new SSHLauncher('atl-pdoci-db-3.us.manh.com', 22, 'oracle', 'oracle99', '', '')

Slave agent = new DumbSlave(
"/home/oracle/slave_jenkins",
launcher)
agent.nodeDescription = "atl-pdoci-db-3.us.manh.com"
agent.numExecutors = 5
agent.labelString = "atl-pdoci-db-3.us.manh.com"
agent.mode = Node.Mode.NORMAL
agent.retentionStrategy = new RetentionStrategy.Always()





Node nodetest= Jenkins.instance.getNode("atl-pdoci-db-3.us.manh.com")
if(nodetest==null)
{
Jenkins.instance.addNode(agent)
println("node created")
}
else
{
println("node already exists::"+nodetest)

}


Victor Martinez

unread,
Oct 17, 2017, 4:18:31 AM10/17/17
to job-dsl-plugin
Hi there,

I've used something similar but different in some way in the past rather than the JobDSL plugin, in my case I used https://wiki.jenkins.io/display/JENKINS/Groovy+plugin which might help you to run your snippet, and therefore you can get all the benefits of versioning those scripts in your SCM and use them within Jenkins.

Besides of that, there is already an active project which might be interesting to look it at
Cheers

Reply all
Reply to author
Forward
0 new messages