# Environment variable support for timer values

**URL:** <https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [July 25, 2021, 4:18pm UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076 "2021-07-25T16:18:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![crirvine](https://forum.camunda.io/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@crirvine](https://forum.camunda.io/u/crirvine)\
**Post date:** [July 25, 2021, 4:18pm UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076/1 "2021-07-25T16:18:54Z")

</div>

I would like for my timer values to be pulled from environment variables. For example, we have a process with a timer cycle start event. We want this value to be determined dynamically based on the environment, that is, dev, test, prod, etc. Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![aravindhrs](https://forum.camunda.io/user_avatar/forum.camunda.io/aravindhrs/32/32503_2.png) [@aravindhrs](https://forum.camunda.io/u/aravindhrs)\
**Post date:** [July 25, 2021, 4:40pm UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076/2 "2021-07-25T16:40:25Z")

</div>

@crirvine You can utilize the same variable across environments and configure the value according to the environments.

From docs, [Timer Events | docs.camunda.org](https://docs.camunda.org/manual/7.15/reference/bpmn20/events/timer-events/)

> You can use expressions for the timer event definitions. By doing so you can influence the timer definition based on process variables. The process variables must contain the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) (or cron for cycle type) string for the appropriate timer type.

```auto
<bpmn:startEvent id="StartProcess" name="Start Process">
  <bpmn:outgoing>Flow_15xrtnn</bpmn:outgoing>
  <bpmn:timerEventDefinition id="TimerEventDefinition_1x4ezt3">
    <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">${duration}</bpmn:timeDuration>
  </bpmn:timerEventDefinition>
</bpmn:startEvent>

```

 ![image](https://forum.camunda.io/uploads/default/original/2X/1/191d8dcb1fc605c0d699dbb626324c6e5dd71b2c.png)

---

<div class="post-metadata">

**Author:** ![crirvine](https://forum.camunda.io/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@crirvine](https://forum.camunda.io/u/crirvine)\
**Post date:** [July 25, 2021, 6:58pm UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076/3 "2021-07-25T18:58:29Z")

</div>

I was aware that I would provide an expression for the time duration. What I don’t understand is how you import the variable “duration” and its value from what ever environment you happen to be running in.

---

<div class="post-metadata">

**Author:** ![fml2](https://forum.camunda.io/user_avatar/forum.camunda.io/fml2/32/6280_2.png) [@fml2](https://forum.camunda.io/u/fml2)\
**Post date:** [July 25, 2021, 7:30pm UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076/4 "2021-07-25T19:30:28Z")

</div>

Bind the environment variable to a spring property, and then use the property in the timer definition. This assumes that you use spring.

There is a caveat though. The expression is only evaluated on a real model deployment. If you just change the env variable and redeploy the unchanged process model the new schedule will NOT take effect. This was discussed recently here in the forums, with solutions.

---

<div class="post-metadata">

**Author:** ![crirvine](https://forum.camunda.io/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@crirvine](https://forum.camunda.io/u/crirvine)\
**Post date:** [July 25, 2021, 7:36pm UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076/5 "2021-07-25T19:36:36Z")

</div>

Ok. I’ll try that approach. I understand your caveat. Thanks

---

<div class="post-metadata">

**Author:** ![aravindhrs](https://forum.camunda.io/user_avatar/forum.camunda.io/aravindhrs/32/32503_2.png) [@aravindhrs](https://forum.camunda.io/u/aravindhrs)\
**Post date:** [July 26, 2021, 8:11am UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076/6 "2021-07-26T08:11:02Z")

</div>

Hi @crirvine I’ve tried this approach, just try this.

Here’s a code that can be used in expression:

```auto
@Component
public class CamundaUtility {
	
	@Value("${timer.duration:PT5M}")
	private String duration;

	public String getTimerDuration() {
		return this.duration;
	}

}

```

For different environments you can set this field `timer.duration` in jvm args according to the environment and with default value.

**JVM args for various environments looks like:**

For **DEV** environment:

```auto
-Dtimer.duration=PT1M

```

For **TEST** environment:

```auto
-Dtimer.duration=PT2M

```

For **PROD** environment:

```auto
-Dtimer.duration=PT3M

```

**Then deploy this bpmn file and test:** [timerTest.bpmn](https://forum.camunda.io/uploads/short-url/3WQgxGHfWxj6TDGeKoiAGKOQvpe.bpmn) (8.1 KB)

 ![Screenshot 2021-07-26 at 1.39.56 PM](https://forum.camunda.io/uploads/default/original/2X/0/06b6a6da602a6049714eebe188c108670331dbe8.png)

 ![Screenshot 2021-07-26 at 2.50.24 PM](https://forum.camunda.io/uploads/default/original/2X/0/0195ea8ccf0ae74208fd4bf60e569930cd4e4b5c.png)

 ![Screenshot 2021-07-26 at 1.46.10 PM](https://forum.camunda.io/uploads/default/original/2X/1/1ed4ba75c36e9988a48f175e6a9b456106729d36.jpeg)

* * *

* * *

**From below, the intermediate timer catching event also uses expression but this time it refers from process variable `duration` which is set from previous user task**.

**Deploy this bpmn file and test:** [timerTest.bpmn](https://forum.camunda.io/uploads/short-url/zlC7drq3HeK3mLxviABFNni8ToI.bpmn) (8.3 KB)

 ![Screenshot 2021-07-26 at 2.47.09 PM](https://forum.camunda.io/uploads/default/original/2X/6/651bf9b0904bf713c43aff45c83d6438abf55c34.png)

 ![Screenshot 2021-07-26 at 1.51.03 PM](https://forum.camunda.io/uploads/default/original/2X/5/59eea81cc9e0b45f8ed4d2c3b676d36db5fbe98e.png)

 ![Screenshot 2021-07-26 at 1.53.33 PM](https://forum.camunda.io/uploads/default/original/2X/e/ecccf2769df335543c92310310da81f63bb5e8a1.png)

---

<div class="post-metadata">

**Author:** ![crirvine](https://forum.camunda.io/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@crirvine](https://forum.camunda.io/u/crirvine)\
**Post date:** [July 26, 2021, 12:01pm UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076/7 "2021-07-26T12:01:35Z")

</div>

Wow. What a generous reply. Thanks so much. This will be very helpful I’m sure.

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 1:15pm UTC](https://forum.camunda.io/t/environment-variable-support-for-timer-values/29076/8 "2024-01-30T13:15:36Z")

</div>

Closed on January 30, 2024, 1:15pm UTC


