In the following example, I have a small web application that uses spring where I inject the url of the external service I want to use into a java class. I have a different url for different environments. Now I want to pass the environment I want to pass al the way from bamboo2 to java and spring. So from bamboo I will be able to define a plan for every environment so that I will be able to test every environment, deploy to every environment and so on.
I am assuming you have a good knowledge about spring, bamboo, maven and unit testing in general and the only thing you do not know is how to make it more generic.
Properties file:
configuration-local.properties:app.url=http://localhost:8080/app
configuration-testing.properties:
app.url=http://testing:8080/app
configuration-production.properties:
app.url=http://production:8080/appSo we have a file for each configuration.
Spring config file:
applicationContext.xml:
<beans
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="propertyConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE">
<property name="location" value="classpath:configuration-${env}.properties">
</property></property></bean>
<bean class="com.miguel.app.App" id="app">
<property name="url" value="${app.url}">
</property></bean>
</beans>
Maven
Configure surefire plugin:
<plugin>
<artifactid>maven-surefire-plugin</artifactid>
<configuration>
<environmentvariables>
<env>${env}</env>
</environmentvariables>
<systemproperties>
<property>
<name>env</name>
<value>${env}</value>
</property>
</systemproperties>
</configuration>
</plugin>
Bamboo:
In the plan go to configure jobset the goal:
test -Denv=dev