# Setting cancel grace period on agent-stack-k8s

**URL:** <https://forum.buildkite.community/t/setting-cancel-grace-period-on-agent-stack-k8s/4161>\
**Category:** General\
**Created:** [January 8, 2025, 9:45pm UTC](https://forum.buildkite.community/t/setting-cancel-grace-period-on-agent-stack-k8s/4161 "2025-01-08T21:45:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathanyeong](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jonathanyeong](https://forum.buildkite.community/u/jonathanyeong)\
**Post date:** [January 8, 2025, 9:45pm UTC](https://forum.buildkite.community/t/setting-cancel-grace-period-on-agent-stack-k8s/4161/1 "2025-01-08T21:45:29Z")

</div>

Hey BuildKite team, what is the best way to set `cancel-grace-period`? Should we set it as an ENV var for the agent? Where would we set that ENV var? I noticed that there’s an `agent-config` in the agent-stack-k8s configuration but `cancel-grace-period` is not an available option.

---

<div class="post-metadata">

**Author:** ![suma](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/suma/32/1306_2.png) [@suma](https://forum.buildkite.community/u/suma)\
**Post date:** [January 8, 2025, 11:41pm UTC](https://forum.buildkite.community/t/setting-cancel-grace-period-on-agent-stack-k8s/4161/2 "2025-01-08T23:41:57Z")

</div>

Hi @jonathanyeong 👋,

This is Suma from Buildkite support team. Thank you for reaching out to us with your question.

There are couple of approaches you can take, one is to define env `BUILDKITE_CANCEL_GRACE_PERIOD` at pipeline level or if you are using custom agent image then in the config file provided to that agent image you can configure it so all pipelines running on the stack will get this.

Please let us know if you have any questions.

Thanks,  
Suma

---

<div class="post-metadata">

**Author:** ![jonathanyeong](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jonathanyeong](https://forum.buildkite.community/u/jonathanyeong)\
**Post date:** [January 9, 2025, 3:51pm UTC](https://forum.buildkite.community/t/setting-cancel-grace-period-on-agent-stack-k8s/4161/3 "2025-01-09T15:51:52Z")

</div>

Hey @suma thank you so much for the reply!

We’re using `agent-stack-k8s` will that pick up the env var `BUILDKITE_CANCEL_GRACE_PERIOD` if it’s set at the pipeline level?

```auto
agents:
  queue: kubernetes
env:
  BUILDKITE_CANCEL_GRACE_PERIOD: 1800 # 30 minutes
steps:
<steps here>

```

It seems like the agent isn’t picking up the grace period even though I can see the environment variable set on the containers.

---

<div class="post-metadata">

**Author:** ![suma](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/suma/32/1306_2.png) [@suma](https://forum.buildkite.community/u/suma)\
**Post date:** [January 9, 2025, 5:50pm UTC](https://forum.buildkite.community/t/setting-cancel-grace-period-on-agent-stack-k8s/4161/4 "2025-01-09T17:50:13Z")

</div>

Hey @jonathanyeong,

Please share the agent version you are using so I can perform a test on my end to see why it is not working even though env is available.

Thanks,  
Suma

---

<div class="post-metadata">

**Author:** ![jonathanyeong](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jonathanyeong](https://forum.buildkite.community/u/jonathanyeong)\
**Post date:** [January 9, 2025, 6:33pm UTC](https://forum.buildkite.community/t/setting-cancel-grace-period-on-agent-stack-k8s/4161/5 "2025-01-09T18:33:39Z")

</div>

We’re running `agent-stack-k8s` 0.19.2 which I believe runs agent `3.87.0`.

---

<div class="post-metadata">

**Author:** ![suma](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/suma/32/1306_2.png) [@suma](https://forum.buildkite.community/u/suma)\
**Post date:** [January 10, 2025, 6:18pm UTC](https://forum.buildkite.community/t/setting-cancel-grace-period-on-agent-stack-k8s/4161/6 "2025-01-10T18:18:40Z")

</div>

Hey @jonathanyeong,

I also performed a test and can see that the cancel grace period is getting set. Please send us an email at [support@buildkite.com](mailto:support@buildkite.com) with the build you ran where you see it did not respect the cancel grace period so we can take a further look into this issue.

Thanks,  
Suma
