diff --git a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java index 5656c79b7..0b2cd4330 100644 --- a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java +++ b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java @@ -961,7 +961,11 @@ private void setupRootDevice(List deviceMappings) { LOGGER.warning("AMI missing block devices"); return; } - BlockDeviceMapping rootMapping = rootDeviceMappings.get(0); + BlockDeviceMapping rootMapping = getRootDeviceMapping(rootDeviceMappings); + if (rootMapping==null) { + LOGGER.warning("AMI missing root device"); + return; + } LOGGER.info("AMI had " + rootMapping.getDeviceName()); LOGGER.info(rootMapping.getEbs().toString()); @@ -984,6 +988,12 @@ private void setupRootDevice(List deviceMappings) { } } + private BlockDeviceMapping getRootDeviceMapping(List deviceMappings) { + return deviceMappings.stream().filter(mapping -> mapping.getDeviceName().equals(getImage().getRootDeviceName())) + .findFirst() + .orElse(null); + } + private List getNewEphemeralDeviceMapping() { final List oldDeviceMapping = getAmiBlockDeviceMappings();