Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ work
.project
.classpath
.settings
.idea
vsphere-cloud.iml
*.log

/nb-configuration.xml
/nbactions.xml
/nbactions.xml
60 changes: 42 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.609.2</version><!-- which version of Jenkins is this plugin built against? -->
<version>2.6</version>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? This will require every user to be Jenkins 2.6 - not yet released. And not everyone is upgrading to the very latest and greatest immediately. Can a lower version be safely used?

Copy link
Copy Markdown
Member Author

@witokondoria witokondoria May 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like org.jenkins-ci.plugins:plugin since ver. 2 decouples jenkins.version from pom version (see jenkinsci/plugin-pom/blob/master/README.md). For parent 2.6, the jenkins version to be build to is 1.625.3

A lower versión could be used, indeed.

Neverthless, I'm currently using a snapshot with this PR on a Jenkins 2.4
and is working (so there seems no API changes has been made).

Will try on Monday to lower that parent, rebuild and retest.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that the minimum version still targets 2.6. That works, but will force everyone to upgrade their Jenkins. And there's a security fix in the 2.x line that has broken several plugins, so the adoption rate isn't that good. Were you able to retest with a lower version of Jenkins than 2.6?

</parent>

<artifactId>vsphere-cloud</artifactId>
Expand Down Expand Up @@ -69,24 +69,48 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1.15</version>
<version>1.28</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.vmware</groupId>
<artifactId>vijava</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>node-iterator-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>com.toastcoders</groupId>
<artifactId>yavijava</artifactId>
<version>6.0.03</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>node-iterator-api</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>

<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<configuration>
<disabledTestInjection>true</disabledTestInjection>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Describable;
import hudson.model.AbstractBuild;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.slaves.Cloud;
import hudson.model.*;

import jenkins.tasks.SimpleBuildStep;
import org.jenkinsci.plugins.vSphereCloud;
import org.jenkinsci.plugins.vsphere.builders.Messages;
import org.jenkinsci.plugins.vsphere.tools.VSphere;
import org.jenkinsci.plugins.vsphere.tools.VSphereException;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import javax.annotation.Nonnull;
import java.io.IOException;

/**
* Define a base class for all vSphere build steps. All vSphere build steps should extend
Expand All @@ -45,12 +47,18 @@ public void setVsphere(VSphere vsphere) {
this.vsphere = vsphere;
}

public String getIP() {
return "";
}

public static DescriptorExtensionList<VSphereBuildStep, VSphereBuildStepDescriptor> all() {
return Hudson.getInstance().getDescriptorList(VSphereBuildStep.class);
}

public abstract boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) throws Exception;

public abstract void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException;

public VSphereBuildStepDescriptor getDescriptor() {
return (VSphereBuildStepDescriptor)Hudson.getInstance().getDescriptor(getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,19 @@
*/
package org.jenkinsci.plugins.vsphere;

import hudson.DescriptorExtensionList;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.*;
import hudson.init.InitMilestone;
import hudson.init.Initializer;
import hudson.model.BuildListener;
import hudson.model.Items;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.*;
import hudson.slaves.Cloud;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.ListBoxModel;

import java.io.IOException;
import java.io.PrintStream;

import jenkins.tasks.SimpleBuildStep;
import org.jenkinsci.plugins.vSphereCloud;
import org.jenkinsci.plugins.vsphere.VSphereBuildStep.VSphereBuildStepDescriptor;
import org.jenkinsci.plugins.vsphere.builders.Messages;
Expand All @@ -40,7 +35,9 @@
import org.jenkinsci.plugins.vsphere.tools.VSphereLogger;
import org.kohsuke.stapler.DataBoundConstructor;

public class VSphereBuildStepContainer extends Builder {
import javax.annotation.Nonnull;

public class VSphereBuildStepContainer extends Builder implements SimpleBuildStep {

public static final String SELECTABLE_SERVER_NAME = "${VSPHERE_CLOUD_NAME}";

Expand Down Expand Up @@ -68,13 +65,15 @@ public VSphereBuildStep getBuildStep() {
}

@Override
public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) {
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
VSphere vsphere = null;
try {
EnvVars env = build.getEnvironment(listener);
env.overrideAll(build.getBuildVariables()); // Add in matrix axes..
String expandedServerName = env.expand(serverName);

String expandedServerName = serverName;
if (run instanceof AbstractBuild) {
EnvVars env = (run.getEnvironment(listener));
env.overrideAll(((AbstractBuild) run).getBuildVariables()); // Add in matrix axes..
expandedServerName = env.expand(serverName);
}
startLogs(listener.getLogger(), expandedServerName);
//Need to ensure this server is same as one that was previously saved.
//TODO - also need to improve logging here.
Expand All @@ -87,16 +86,19 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
}

buildStep.setVsphere(vsphere);
if (run instanceof AbstractBuild) {
buildStep.perform(((AbstractBuild) run), launcher, (BuildListener) listener);
} else {
buildStep.perform(run, filePath, launcher, listener);
}

return buildStep.perform(build, launcher, listener);
} catch (Exception e) {
VSphereLogger.vsLogger(listener.getLogger(), e);
throw new AbortException(e.getMessage());
} finally {
if (vsphere != null) {
vsphere.disconnect();
}
}
return false;
}

private void startLogs(PrintStream logger, String serverName){
Expand Down
Loading