ingenieux/beanstalker

-Dbeanstalk.environmentRef parameter does not overwrite value in pom.xml

szantopeter opened this issue · 1 comments

I have the below configuration

<plugin>
    <groupId>br.com.ingenieux</groupId>
    <artifactId>beanstalk-maven-plugin</artifactId>
    <version>1.5.0</version>
    <configuration>
        <applicationName>spring-boot-aws-elasticbeanstalk-example</applicationName>
        <s3Bucket>spring-boot-aws-example</s3Bucket>
        <s3Key>${project.artifactId}/${project.build.finalName}.jar</s3Key>
        <cnamePrefix>spring-boot-aws-elasticbeanstalk-example-dev</cnamePrefix>
        <environmentName>dev</environmentName>
        <environmentRef>dev</environmentRef>
        <solutionStack>64bit Amazon Linux 2016.09 v2.4.0 running Java 8</solutionStack>
    </configuration>
</plugin>

When I run it this way

mvn beanstalk:upload-source-bundle beanstalk:create-application-version beanstalk:update-environment beanstalk:wait-for-environment -Dbeanstalk.environmentRef=staging

the environment name is still coming from the pom.xml, however if I remove the from the pom.xml then the -Dbeanstalk.environmentRef parameter starts to take effect. It would be really nice if I could store a default value in pom.xml, but be able to overwrite it from the command line.

This can be done with maven

Once of the approach is to define your variable.

<properties>
   <MyEnvironmentRef>dev</MyEnvironmentRef>
   <aws.region>us-east-1</aws.region>
</properties>

 <plugin>
    <groupId>br.com.ingenieux</groupId>
    <artifactId>beanstalk-maven-plugin</artifactId>
    <version>1.5.0</version>
    <configuration>
        <regionName>${aws.region}</regionName>
        <applicationName>spring-boot-aws-elasticbeanstalk-example</applicationName>
        <s3Bucket>spring-boot-aws-example-${aws.region}</s3Bucket>
        <s3Key>${project.artifactId}/${project.build.finalName}.jar</s3Key>
        <cnamePrefix>spring-boot-aws-elasticbeanstalk-example-dev</cnamePrefix>
        <environmentName>${MyEnvironmentRef}</environmentName>
        <environmentRef>${MyEnvironmentRef}</environmentRef>
        <solutionStack>64bit Amazon Linux 2016.09 v2.4.0 running Java 8</solutionStack>
    </configuration>
</plugin>

mvn -DMyEnvironmentRef=staging

Alternatively you can use maven profiles to define multiple defaults per each environment as profile.

        <profile>
            <id>prod-ca</id>
            <properties>
                <aws.region>ca-central-1</aws.region>
                <MyEnvironmentRef>prod</MyEnvironmentRef>
            </properties>
        </profile>

mvn -P prod-ca