From 6950e8bf062ae80d2409a2b4d0274cc95437fe05 Mon Sep 17 00:00:00 2001 From: igreenfi Date: Thu, 22 Dec 2016 11:05:31 +0200 Subject: [PATCH] Add new parameter 'ignoreIfNotExists' --- .../plugins/vsphere/builders/PowerOff.java | 21 +++++++++++++++---- .../vsphere/builders/PowerOff/config.jelly | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/vsphere/builders/PowerOff.java b/src/main/java/org/jenkinsci/plugins/vsphere/builders/PowerOff.java index 75cc6e47..3bfc082a 100644 --- a/src/main/java/org/jenkinsci/plugins/vsphere/builders/PowerOff.java +++ b/src/main/java/org/jenkinsci/plugins/vsphere/builders/PowerOff.java @@ -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() { @@ -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; } diff --git a/src/main/resources/org/jenkinsci/plugins/vsphere/builders/PowerOff/config.jelly b/src/main/resources/org/jenkinsci/plugins/vsphere/builders/PowerOff/config.jelly index 294bf44a..86799e4a 100644 --- a/src/main/resources/org/jenkinsci/plugins/vsphere/builders/PowerOff/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/vsphere/builders/PowerOff/config.jelly @@ -25,6 +25,9 @@ limitations under the License. + + +