From 1fc37735bcfd1e9a4d828faa2c1acf3d9d1273db Mon Sep 17 00:00:00 2001 From: Alex Jurkiewicz Date: Tue, 31 Mar 2020 15:47:46 +1100 Subject: [PATCH] If application version already exists, use it --- lib/dpl/providers/elasticbeanstalk.rb | 32 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/dpl/providers/elasticbeanstalk.rb b/lib/dpl/providers/elasticbeanstalk.rb index 076838010..d1567f43e 100644 --- a/lib/dpl/providers/elasticbeanstalk.rb +++ b/lib/dpl/providers/elasticbeanstalk.rb @@ -109,16 +109,28 @@ def upload end def create_version - @version = eb.create_application_version( - application_name: app, - version_label: label, - description: clean(description[0, 200]), - source_bundle: { - s3_bucket: bucket.name, - s3_key: object.key - }, - auto_create_application: false - ) + begin + @version = eb.create_application_version( + application_name: app, + version_label: label, + description: clean(description[0, 200]), + source_bundle: { + s3_bucket: bucket.name, + s3_key: object.key + }, + auto_create_application: false + ) + rescue rescue Aws::ElasticBeanstalk::Errors::ServiceError => e + raise e unless e.message.match?(/^Application Version %{version_label} already exists.$/) + info "%{e.message} Will use this version and proceed." + ver = eb.describe_application_versions({ + application_name: app, + version_labels: [label], + }).application_versions[0] + @version = { application_version: ver } + end + + end def update_app