Hi,
Currently I am passing bamboo variable into custom java progam as below:
-Drlm.PlanName=${bamboo.planName} -jar get.jar
I would like not to pass ${bamboo.planName} through property. is there anyway to consume this variable directly into external java program. say example:
-jar get.jar
should print ${bamboo.planName} variable value.
Thanks
Siddu
Community moderators have prevented the ability to post new answers.
Hello Siddu,
The "${bamboo.planName}" is a variable that is created during execution time and it is for Bamboo's internal use. However, you are able to get the environment variable version ("bamboo_planName").
You are able to run the following Java code and compile it just to make sure the variable can be printed, however, replying to your inquire the same should be called as System.getenv("bamboo_planName") in your Java code.
import java.util.Map; public class EnvMap { public static void main (String[] args) { Map<String, String> env = System.getenv(); for (String envName : env.keySet()) { System.out.format("%s=%s%n", envName, env.get(envName)); } System.out.println(":: PlanName :: " + System.getenv("bamboo_planName")); } }
Go to Bamboo and add a Script task to your plan as per following:
echo "# =========================== #" echo "# Compile the Program" echo "# =========================== #" javac EnvMap.java echo "# =========================== #" echo "# Create manifest" echo "# =========================== #" echo "Main-Class: EnvMap" > manifest.txt echo "# =========================== #" echo "# Create jar" echo "# =========================== #" jar cvfm EnvMap.jar manifest.txt *.class echo "# =========================== #" echo "# Execute JAR" echo "# =========================== #" java -jar EnvMap.jar
In the build result you will find all the environment variables available to the build you are running along with the following entry:
... build 15-Oct-2015 12:11:15 :: PlanName :: Project - Plan ...
If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.
Thank you for your understanding.
—
Kind regards,
Rafael P. Sperafico
Atlassian Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.