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

Add new parameter 'ignoreIfNotExists' #63

Merged
merged 1 commit into from
Jan 2, 2017
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
21 changes: 17 additions & 4 deletions src/main/java/org/jenkinsci/plugins/vsphere/builders/PowerOff.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ public class PowerOff extends VSphereBuildStep implements SimpleBuildStep {
private final boolean evenIfSuspended;
private final boolean shutdownGracefully;


private final boolean ignoreIfNotExists;

@DataBoundConstructor
public PowerOff( final String vm, final boolean evenIfSuspended, final boolean shutdownGracefully) throws VSphereException {
public PowerOff( final String vm, final boolean evenIfSuspended, final boolean shutdownGracefully, final boolean ignoreIfNotExists) throws VSphereException {
this.vm = vm;
this.evenIfSuspended = evenIfSuspended;
this.shutdownGracefully = shutdownGracefully;
this.ignoreIfNotExists = ignoreIfNotExists;
}

public boolean isIgnoreIfNotExists() {
return ignoreIfNotExists;
}

public boolean isEvenIfSuspended() {
Expand Down Expand Up @@ -118,12 +126,17 @@ private boolean powerOff(final Run<?, ?> run, Launcher launcher, final TaskListe

VSphereLogger.vsLogger(jLogger, "Shutting Down VM " + expandedVm + "...");
VirtualMachine vsphereVm = vsphere.getVmByName(expandedVm);
if (vsphereVm == null) {
if (vsphereVm == null && !ignoreIfNotExists) {
throw new RuntimeException(Messages.validation_notFound("vm " + expandedVm));
}
vsphere.powerOffVm( vsphereVm, evenIfSuspended, shutdownGracefully);

VSphereLogger.vsLogger(jLogger, "Successfully shutdown \""+expandedVm+"\"");
if (vsphereVm != null) {
vsphere.powerOffVm(vsphereVm, evenIfSuspended, shutdownGracefully);

VSphereLogger.vsLogger(jLogger, "Successfully shutdown \"" + expandedVm + "\"");
} else {
VSphereLogger.vsLogger(jLogger, "Does not exists, BUT ignore it! \"" + expandedVm + "\"");
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ limitations under the License.
<f:entry title="${%Shutdown gracefully?}" field="shutdownGracefully">
<f:checkbox />
</f:entry>
<f:entry title="${%ignore If Not Exists?}" field="ignoreIfNotExists">
<f:checkbox />
</f:entry>

<f:validateButton title="${%Check Data}" progress="${%Testing...}" method="testData" with="serverName,vm"/>
</j:jelly>