Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NodeProperties config on vSphere template #105

Merged
merged 4 commits into from
Aug 22, 2019
Merged
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
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>vsphere-cloud</artifactId>
<version>2.21-SNAPSHOT</version>
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>

<name>vSphere Plugin</name>
Expand Down Expand Up @@ -45,6 +45,8 @@
</scm>

<properties>
<revision>2.21</revision>
<changelist>-SNAPSHOT</changelist>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jenkinsci/plugins/vSphereCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ public static List<vSphereCloud> findAllVsphereClouds(String jobName) {

TopLevelItem topLevelItem = null;
if (prevFolder == null) {
topLevelItem = Jenkins.getActiveInstance().getItem(item);
topLevelItem = Jenkins.getInstance().getItem(item);
} else {
Collection<TopLevelItem> items = prevFolder.getItems();
for (TopLevelItem levelItem : items) {
Expand Down
38 changes: 34 additions & 4 deletions src/main/java/org/jenkinsci/plugins/vSphereCloudSlaveTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import hudson.model.labels.LabelAtom;
import hudson.plugins.sshslaves.SSHLauncher;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.slaves.CommandLauncher;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.JNLPLauncher;
Expand All @@ -48,6 +49,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nonnull;

import jenkins.model.Jenkins;
import jenkins.slaves.JnlpSlaveAgentProtocol;

Expand All @@ -59,6 +62,8 @@
import org.jenkinsci.plugins.vsphere.tools.VSphere;
import org.jenkinsci.plugins.vsphere.tools.VSphereDuplicateException;
import org.jenkinsci.plugins.vsphere.tools.VSphereException;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -426,7 +431,7 @@ private vSphereCloudProvisionedSlave provision(final String cloneName, final Pri
LOGGER.log(Level.SEVERE, "VM {0} name clashes with one we wanted to use, but it wasn't started by this plugin.", cloneName );
throw ex;
}
final String ourJenkinsUrl = Jenkins.getActiveInstance().getRootUrl();
final String ourJenkinsUrl = Jenkins.getInstance().getRootUrl();
if ( vmJenkinsUrl.equals(ourJenkinsUrl) ) {
LOGGER.log(Level.INFO, "Found existing VM {0} that we started previously (and must have either lost track of it or failed to delete it).", cloneName );
} else {
Expand All @@ -451,7 +456,11 @@ private vSphereCloudProvisionedSlave provision(final String cloneName, final Pri
final ComputerLauncher configuredLauncher = determineLauncher(vSphere, cloneName);
final RetentionStrategy<?> configuredStrategy = determineRetention();
final String snapshotNameForLauncher = ""; /* we don't make the launcher do anything with snapshots because our clone won't be created with any */
slave = new vSphereCloudProvisionedSlave(cloneName, this.templateDescription, this.remoteFS, String.valueOf(this.numberOfExecutors), this.mode, this.labelString, configuredLauncher, configuredStrategy, this.nodeProperties, this.parent.getVsDescription(), cloneName, this.forceVMLaunch, this.waitForVMTools, snapshotNameForLauncher, String.valueOf(this.launchDelay), null, String.valueOf(this.limitedRunCount));
slave = new vSphereCloudProvisionedSlave(cloneName, getTemplateDescription(), getRemoteFS(),
String.valueOf(getNumberOfExecutors()), getMode(), getLabelString(), configuredLauncher,
configuredStrategy, Util.fixNull(getNodeProperties()), getParent().getVsDescription(), cloneName,
getForceVMLaunch(), getWaitForVMTools(), snapshotNameForLauncher, String.valueOf(getLaunchDelay()),
null, String.valueOf(getLimitedRunCount()));
} finally {
// if anything went wrong, try to tidy up
if( slave==null ) {
Expand Down Expand Up @@ -608,6 +617,27 @@ public static List<Descriptor<RetentionStrategy<?>>> getRetentionStrategyDescrip
result.add(VSphereCloudRetentionStrategy.DESCRIPTOR);
return result;
}

/**
* Returns the list of {@link NodePropertyDescriptor} appropriate for the
* {@link vSphereCloudSlave}s that are created from this template.
*
* @return the filtered list
*/
@SuppressWarnings("unchecked")
@Nonnull
@Restricted(NoExternalUse.class) // used by Jelly EL only
public List<NodePropertyDescriptor> getNodePropertiesDescriptors() {
List<NodePropertyDescriptor> result = new ArrayList<NodePropertyDescriptor>();
final Jenkins j = Jenkins.getInstance();
final List<NodePropertyDescriptor> list = j.getDescriptorList(NodeProperty.class);
for (NodePropertyDescriptor npd : list) {
if (npd.isApplicable(vSphereCloudSlave.class)) {
result.add(npd);
}
}
return result;
}
}

private static String findWhichJenkinsThisVMBelongsTo(final VSphere vSphere, String cloneName) {
Expand Down Expand Up @@ -645,7 +675,7 @@ private Map<String, String> calculateExtraConfigParameters(final String cloneNam
throws IOException, InterruptedException {
final EnvVars knownVariables = calculateVariablesForGuestInfo(cloneName, listener);
final Map<String, String> result = new LinkedHashMap<String, String>();
final String jenkinsUrl = Jenkins.getActiveInstance().getRootUrl();
final String jenkinsUrl = Jenkins.getInstance().getRootUrl();
if (jenkinsUrl != null) {
result.put(VSPHERE_ATTR_FOR_JENKINSURL, jenkinsUrl);
}
Expand All @@ -667,7 +697,7 @@ private EnvVars calculateVariablesForGuestInfo(final String cloneName, final Tas
final EnvVars knownVariables = new EnvVars();
// Maintenance note: If you update this method, you must also update the
// UI help page to match.
final String jenkinsUrl = Jenkins.getActiveInstance().getRootUrl();
final String jenkinsUrl = Jenkins.getInstance().getRootUrl();
if (jenkinsUrl != null) {
addEnvVar(knownVariables, "JENKINS_URL", jenkinsUrl);
addEnvVar(knownVariables, "HUDSON_URL", jenkinsUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public ListBoxModel doFillServerNameItems(@AncestorInPath Item context) {

TopLevelItem topLevelItem = null;
if (prevFolder == null) {
topLevelItem = Jenkins.getActiveInstance().getItem(item);
topLevelItem = Jenkins.getInstance().getItem(item);
} else {
Collection<TopLevelItem> items = prevFolder.getItems();
for (TopLevelItem levelItem : items) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<f:checkbox/>
</f:entry>

<f:entry title="${%Delay between launch and boot complete}" field="launchDelay" description="${%Number of seconds.}">
<f:entry title="${%Delay in seconds}" field="launchDelay">
<f:textbox clazz="required number" default="60"/>
</f:entry>

Expand Down Expand Up @@ -121,7 +121,10 @@
</j:forEach>
</f:dropdownList>

<f:descriptorList title="${%Node Properties}" descriptors="${h.getNodePropertyDescriptors(descriptor.clazz)}" field="nodeProperties"/>
<f:entry title="Node Properties">
<f:repeatableHeteroProperty field="nodeProperties" oneEach="true" hasHeader="true"
addCaption="Add Node Property" deleteCaption="Delete Node Property"/>
</f:entry>
</f:advanced>

<f:entry title="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ f.entry(title:_("vSphere Host"), field:"vsHost") {
f.textbox()
}

f.entry(title:_("Disable Certificate Verification"), field:"allowUntrustedCertificate") {
f.entry(title:_("Disable SSL Check"), field:"allowUntrustedCertificate") {
f.checkbox()
}

Expand Down