-
Notifications
You must be signed in to change notification settings - Fork 411
/
create-shared-agent.groovy
40 lines (37 loc) · 1.61 KB
/
create-shared-agent.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
Author: kuisathaverat
create a shared Agent JNLP from groovy
**/
import com.cloudbees.opscenter.server.jnlp.slave.JocJnlpSlaveLauncher
import com.cloudbees.opscenter.server.model.SharedNodeRetentionStrategy
import com.cloudbees.opscenter.server.model.SharedSlave
import com.cloudbees.opscenter.server.properties.EnvironmentVariablesNodePropertyCustomizer
import com.cloudbees.opscenter.server.properties.NodePropertyCustomizer
import com.cloudbees.opscenter.server.properties.SharedSlaveNodePropertyCustomizer
import hudson.model.Node
import hudson.slaves.EnvironmentVariablesNodeProperty
import hudson.tools.ToolLocationNodeProperty
import hudson.tools.ToolProperty
import com.cloudbees.opscenter.server.model.*
SharedSlave instance = jenkins.model.Jenkins.getInstance().createProject(SharedSlave.class,"ShareAgentName")
instance.setLauncher(new JocJnlpSlaveLauncher("tunnel:10000", "-Xmx256m", "-noCertificateCheck"))
instance.setNumExecutors(5)
instance.setLabelString("foo bar manchu")
instance.setMode(Node.Mode.EXCLUSIVE)
instance.setRemoteFS("/home/foo")
instance.getProperties().add(
new SharedSlaveNodePropertyCustomizer(
Arrays. < NodePropertyCustomizer > asList(
new EnvironmentVariablesNodePropertyCustomizer(
new EnvironmentVariablesNodeProperty(
Arrays.asList(
new EnvironmentVariablesNodeProperty.Entry("x", "y"),
new EnvironmentVariablesNodeProperty.Entry("a", "b")
)
)
)
)
)
);
instance.setRetentionStrategy(new SharedNodeRetentionStrategy())
instance.save()