@@ -43,11 +43,19 @@ public class PowerOff extends VSphereBuildStep implements SimpleBuildStep {
4343 private final boolean evenIfSuspended ;
4444 private final boolean shutdownGracefully ;
4545
46+
47+ private final boolean ignoreIfNotExists ;
48+
4649 @ DataBoundConstructor
47- public PowerOff ( final String vm , final boolean evenIfSuspended , final boolean shutdownGracefully ) throws VSphereException {
50+ public PowerOff ( final String vm , final boolean evenIfSuspended , final boolean shutdownGracefully , final boolean ignoreIfNotExists ) throws VSphereException {
4851 this .vm = vm ;
4952 this .evenIfSuspended = evenIfSuspended ;
5053 this .shutdownGracefully = shutdownGracefully ;
54+ this .ignoreIfNotExists = ignoreIfNotExists ;
55+ }
56+
57+ public boolean isIgnoreIfNotExists () {
58+ return ignoreIfNotExists ;
5159 }
5260
5361 public boolean isEvenIfSuspended () {
@@ -118,12 +126,17 @@ private boolean powerOff(final Run<?, ?> run, Launcher launcher, final TaskListe
118126
119127 VSphereLogger .vsLogger (jLogger , "Shutting Down VM " + expandedVm + "..." );
120128 VirtualMachine vsphereVm = vsphere .getVmByName (expandedVm );
121- if (vsphereVm == null ) {
129+ if (vsphereVm == null && ! ignoreIfNotExists ) {
122130 throw new RuntimeException (Messages .validation_notFound ("vm " + expandedVm ));
123131 }
124- vsphere .powerOffVm ( vsphereVm , evenIfSuspended , shutdownGracefully );
125132
126- VSphereLogger .vsLogger (jLogger , "Successfully shutdown \" " +expandedVm +"\" " );
133+ if (vsphereVm != null ) {
134+ vsphere .powerOffVm (vsphereVm , evenIfSuspended , shutdownGracefully );
135+
136+ VSphereLogger .vsLogger (jLogger , "Successfully shutdown \" " + expandedVm + "\" " );
137+ } else {
138+ VSphereLogger .vsLogger (jLogger , "Does not exists, BUT ignore it! \" " + expandedVm + "\" " );
139+ }
127140
128141 return true ;
129142 }
0 commit comments