Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ When you want the slaves to be dynamically provisioned based on a template, choo

To add a node, go to `Manage Jenkins` > `Manage Nodes` > `New Node` and choose `Slave virtual computer running on scripted cloud`. You can configure which scripted cloud to use in the next screen of the wizard.

**Attention:** When `reusable` is turned of, this node will be deleted after the next usage.
**Attention:** When `reusable` is turned off, this node will be deleted after the next usage.
31 changes: 28 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.2</version><!-- which version of Jenkins is this plugin built against? -->
<version>4.16</version><!-- which version of Jenkins is this plugin built against? -->
<relativePath />
</parent>

<artifactId>scripted-cloud-plugin</artifactId>
Expand Down Expand Up @@ -43,19 +44,43 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<guice.version>3.0</guice.version>
<ivy.plugin.version>1.19</ivy.plugin.version>
<jenkins.version>2.249.1</jenkins.version>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.26</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public synchronized Collection<NodeProvisioner.PlannedNode> provision(Label labe
final List<ScriptedCloudSlaveTemplate> templates = getMatchingTemplates(label);

for (ScriptedCloudSlaveTemplate t : templates) {
LOGGER.log(Level.INFO, "Template: " + t.getDescription());
LOGGER.log(Level.INFO, String.format("Template: %s", t.getDescription()));

boolean canProvision = true;

Expand Down Expand Up @@ -123,7 +123,7 @@ private boolean canProvisionSlaveTemplate(@Nonnull ScriptedCloudSlaveTemplate te
}

private int getTemplateInstancesCount(@Nonnull ScriptedCloudSlaveTemplate template) {
Computer[] computers = Jenkins.getInstance().getComputers();
Computer[] computers = Jenkins.get().getComputers();

int count = 0;
for (Computer computer : computers){
Expand All @@ -138,7 +138,7 @@ private int getTemplateInstancesCount(@Nonnull ScriptedCloudSlaveTemplate templa
}

private int getInstancesCount() {
Computer[] computers = Jenkins.getInstance().getComputers();
Computer[] computers = Jenkins.get().getComputers();

int count = 0;
for (Computer computer : computers){
Expand Down Expand Up @@ -188,7 +188,7 @@ public Node call() throws Exception {
template.getSecToWaitOnline(),
template.getReusable());

Jenkins.getInstance().addNode(slave);
Jenkins.get().addNode(slave);


LOGGER.log(Level.INFO, String.format("Asking ScriptedCloud %s to schedule new Jenkins slave %s", name, slaveName));
Expand Down Expand Up @@ -284,11 +284,11 @@ private void executeCommand(String command, String name, List<EnvironmentVariabl
environmentVariables.forEach(ev -> envVars.put(ev.getKey(), ev.getValue()));

envVars.put("SLAVE_NAME", name);
envVars.put("JENKINS_URL", Jenkins.getInstance().getRootUrl());
envVars.put("JENKINS_URL", Jenkins.get().getRootUrl());

// Support for Jenkins security
if (Jenkins.getInstance().isUseSecurity()) {
envVars.put("JNLP_SECRET", jenkins.slaves.JnlpSlaveAgentProtocol.SLAVE_SECRET.mac(name));
if (Jenkins.get().isUseSecurity()) {
envVars.put("JNLP_SECRET", jenkins.slaves.JnlpAgentReceiver.SLAVE_SECRET.mac(name));
}


Expand All @@ -311,7 +311,7 @@ private void executeCommand(String command, String name, List<EnvironmentVariabl
throw new AbortException("The script failed with exit code " + result);
}

LOGGER.log(Level.FINE, "Script for %s finished successfully.");
LOGGER.log(Level.FINE, String.format("Script for, %s, finished successfully.", command));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void launch(SlaveComputer slaveComputer, TaskListener listener) {
}

if (launched) {
LOGGER.log(INFO, "Agent has already been launched, activating: %s", computer.getDisplayName());
LOGGER.log(INFO, String.format("Agent has been launched, activating: %s", computer.getDisplayName()));
computer.setAcceptingTasks(true);
return;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public void launch(SlaveComputer slaveComputer, TaskListener listener) {
throw new IllegalStateException("Slave did not come online in allowed time");
}
}
LOGGER.log(INFO, "Agent has been launched, activating: %s", computer.getDisplayName());
LOGGER.log(INFO, String.format("Agent has been launched, activating: %s", computer.getDisplayName()));

computer.setAcceptingTasks(true);
} catch (Throwable ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public ScriptedCloudSlave(String name, String nodeDescription,
List<? extends NodeProperty<?>> nodeProperties,
String cloudName, List<EnvironmentVariable> envVars,
String secToWaitOnline, Boolean reusable) throws FormException, IOException {
super(name, nodeDescription, remoteFS, numExecutors, mode, labelString,
new ScriptedCloudLauncher(delegateLauncher, Util.tryParseNumber(secToWaitOnline, 10 * 60).intValue())
, retentionStrategy, nodeProperties);
super(name, remoteFS, new ScriptedCloudLauncher(delegateLauncher, Util.tryParseNumber(secToWaitOnline, 10 * 60).intValue()) );

this.cloudName = cloudName;
this.reusable = reusable;
Expand All @@ -82,7 +80,7 @@ public String getCloudName() {
}

public Cloud getCloud() {
return Jenkins.getInstance().getCloud(getCloudName());
return Jenkins.get().getCloud(getCloudName());
}

public String getSecToWaitOnline() {
Expand All @@ -101,7 +99,7 @@ public int getSecToWaitOnlineInt(){
*/
@Nonnull
public ScriptedCloud getScriptedCloud() {
Cloud cloud = Jenkins.getInstance().getCloud(getCloudName());
Cloud cloud = Jenkins.get().getCloud(getCloudName());
if (cloud instanceof ScriptedCloud) {
return (ScriptedCloud) cloud;
} else {
Expand Down Expand Up @@ -248,7 +246,7 @@ public boolean configure(StaplerRequest req, JSONObject o)

public List<ScriptedCloud> getScriptedClouds() {
List<ScriptedCloud> result = new ArrayList<ScriptedCloud>();
for (Cloud cloud : Jenkins.getInstance().clouds) {
for (Cloud cloud : Jenkins.get().clouds) {
if (cloud instanceof ScriptedCloud) {
result.add((ScriptedCloud) cloud);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
</f:entry>

<f:entry title="${%Batch or a shell script to start machine}" field="startScript">
<f:expandableTextbox/>
<f:textarea/>
</f:entry>

<f:entry title="${%Batch or a shell script to stop machine}" field="stopScript">
<f:expandableTextbox/>
<f:textarea/>
</f:entry>

<f:entry title="${%Slave Templates}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<f:textbox/>
</f:entry>

<f:entry title="${%Executors}" field="numExecutors">
<f:textbox default="1"/>
</f:entry>

<f:entry title="${%Labels}" field="labelString">
<f:textbox/>
</f:entry>
Expand All @@ -53,11 +57,7 @@ description="${%Can this slave be used for multiple builds?}" field="reusable">
<j:set var="descriptor" value="${d}"/>
<j:set var="instance"
value="${it.delegateLauncher.descriptor==d ? it.delegateLauncher : null}"/>
<tr>
<td>
<input type="hidden" name="stapler-class" value="${d.clazz.name}"/>
</td>
</tr>
<f:invisibleEntry><input type="hidden" name="stapler-class" value="${d.clazz.name}"/></f:invisibleEntry>
<st:include from="${d}" page="${d.configPage}" optional="true"/>
</f:dropdownListBlock>
</j:forEach>
Expand All @@ -75,11 +75,7 @@ description="${%Can this slave be used for multiple builds?}" field="reusable">
<j:set var="descriptor" value="${d}"/>
<j:set var="instance"
value="${it.retentionStrategy.descriptor==d ? it.retentionStrategy : null}"/>
<tr>
<td>
<input type="hidden" name="stapler-class" value="${d.clazz.name}"/>
</td>
</tr>
<f:invisibleEntry><input type="hidden" name="stapler-class" value="${d.clazz.name}"/></f:invisibleEntry>
<st:include from="${d}" page="${d.configPage}" optional="true"/>
</f:dropdownListBlock>
</j:if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<f:textbox/>
</f:entry>

<f:slave-mode name="mode" node="${it}"/>

<f:entry title="${%EnvVars}" description="${%List of environment variables to give to start/stop script}">
<f:repeatableHeteroProperty field="envVars" hasHeader="true" addCaption="Add Environment Variable"
deleteCaption="Delete Environment Variable"/>
Expand All @@ -31,11 +33,6 @@
<f:textbox default="600"/>
</f:entry>

<f:entry title="${%Reusable}" description="${%Can this slave be used for multiple builds?}" field="reusable">
<f:checkbox/>
</f:entry>


<f:entry title="${%Remote FS root}" field="remoteFS">
<f:textbox/>
</f:entry>
Expand All @@ -44,12 +41,14 @@
<f:textbox default="1"/>
</f:entry>

<f:entry title="${%Executors}" field="numPreprovisioned" description="${%Number of preprovisioned slaves for this template}">
<f:textbox default="1"/>
<f:entry title="${%Number of preprovisioned instances}" field="numPreprovisioned" description="${%Number of preprovisioned instances for this template}">
<f:textbox default="0"/>
</f:entry>

<f:entry title="${%Reusable}" description="${%Can this slave be used for multiple builds?}" field="reusable">
<f:checkbox/>
</f:entry>

<f:slave-mode name="mode" node="${it}"/>

<!--<f:entry title="">-->
<!--<div align="right">-->
Expand Down