Details
-
Suggestion
-
Resolution: Unresolved
-
None
-
None
-
3
-
Description
Issue description
Bamboo does not pass its Global Variables as Environment Variables to Repository Stored Specs executions of Maven. This would be useful if we wanted to read the value from a Bamboo Global Variable and execute conditional code during Specs Scanning, for example.
Workaround
Currently, the only workaround would be to set the variable outside Bamboo, as an Environment Variable, and read it in the Specs code:
public static final String myVariable = System.getenv("MY_VARIABLE");
However, reading environment variables during a Specs execution requires additional access that Bamboo's JVM doesn't have by default. You need to either:
Option 1 (recommended)
- Locate the Java .policy file under ${JAVA_HOME}/jre/lib/security/. It might be called either default.policy or java.policy. This needs to be done under the Java Home directory of the JDK your Bamboo uses.
- Locate the following section (usually it's the last one):
// permissions needed by applications using java.desktop module grant {
- Add the following permission within the grant { section, replacing MY_VARIABLE with the variable you want to read:
permission java.lang.RuntimePermission "getenv.MY_VARIABLE";
If there are multiple variables, you can either specify all of them (new lines for each), or grant access to ALL env variables using getenv.*
- Save the file and run the Specs Scan.
Option 2 (not recommended due to security risks)
Add the following property to the <bamboo-install>/bin/setenv.sh file and restart Bamboo.
JVM_SUPPORT_RECOMMENDED_ARGS:="-Dbamboo.repository.stored.specs.security.manager.enabled=false"
Please see Configuring your system properties for detailed steps.
Disabling the Specs Security Manager brings some security risks since this way you will allow execution of any code in Specs.