How to find the environment of camunda instance

Hi Team,

I need to read the camunda url from browser at runtime means (writing script in script task to read it) so that I can understand which environment running at the moment and based on that it could use some of the variables

like to find is it dev or uat or prod

can someone help me on this @Niall

Hello my friend! :smile:

I’ll explain how I did it here at my current company.
Our camunda is embedded spring.
Note: Our environment URL is saved as an AWS parameter.

I created a Java class annotating with @Component so that it is recognized by Spring.
And then I created the “getter” attributes and methods to be able to access this myEnvironmentUrl attribute, with getMyEnvironmentUrl.

After creating this class, I put it in application.properties:
env.url=${environment.url} to fetch this value from the AWS parameter store using the SDK.

Then you create a class to use the AWS SDK,

@Configuration
public class AwsSsmConfig implements PropertySourceLocator {

  @Bean("awsClient")
     public AWSSimpleSystemsManagement awsClient() {
         return AWSSimpleSystemsManagementClientBuilder.standard().withCredentials(new DefaultAWSCredentialsProviderChain()).build();
     }

     @Override
     public PropertySource<?> locate(Environment environment) {
         LOG.info("Retrieving config from AWS EC2 parameter store");
         List<GetParametersResult> parameters = new ArrayList<>();
         AWSSimpleSystemsManagement awsClient = awsClient();

         parameters.add(awsClient.getParameters(new GetParametersRequest()
                 .withNames("env.url")));
}

Map<String, Object> config = new HashMap<>();

        parameters.stream()
                .map(GetParametersResult::getParameters)
                .flatMap(List::stream)
                .collect(Collectors.toList())
                .forEach(parameter -> {
                     config.put(parameter.getName(), parameter.getValue());
                 });
        return new MapPropertySource("aws-ssm", config);
        }
}

OBS.: Never more than 10 parameters at a time.

After doing this, you will have access to the url of your environment through the getMyEnvironmentUrl() method and then you will be able to use it to return the URL of your running environment.

And for example if your Camunda is embedded too, and you want to access the URL through an execution listner for example, you can also do it using:

var env = PropertiesService.getMyEnvironmentUrl();

Hope this helps.

William Robert Alves

But in your case, perhaps the most appropriate is to search from the environment variable itself.

for example… Create a Java class with an attribute called camundaEnv and use the annotation @Value("${camunda.env}") In application.properties you create this parameter looking for the environment variable which most of the time has the name of ENV (check the name of the environment variable first).

Do it as follows.

camunda.env=${ENV}

And so you can access the value of the environment variable through this “camundaEnv” attribute, preferably use a getter to fetch this attribute value.

William Robert Alves

Solved? :smiley:

please let us know if your question is resolved!

Hi @WilliamR.Alves thankyou so much for your quick reply and it is making sense to me

but the thing is that my camunda engine is independent of any spring project so I can not write any java class.

The only thing we can use is within the camunda BPMN model like script task or something like execution listener on start event.

Hello my friend!

I understood!

Try doing the following within a “start execution listner” in your Camunda Modeler.

You will need to know the name of the environment variable that was created to pass as an argument to the getenv() method.
In this example below, I used CAMUNDA_DEPLOY_URL, but usually this environment variable is called “ENV”.
Substitute the variable name according to your environment variable.

var camundaDeployUrl = java.lang.System.getenv("CAMUNDA_DEPLOY_URL");

execution.setVariable("camundaDeployUrl", camundaDeployUrl);

This script will fetch the value of the variable from your environment, and save it in a process variable in your camunda.

William Robert Alves

1 Like