# How do you write and execute pre or post-command script in buildkite?

**URL:** <https://forum.buildkite.community/t/how-do-you-write-and-execute-pre-or-post-command-script-in-buildkite/2054>\
**Category:** General\
**Created:** [May 26, 2022, 4:13am UTC](https://forum.buildkite.community/t/how-do-you-write-and-execute-pre-or-post-command-script-in-buildkite/2054 "2022-05-26T04:13:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [May 26, 2022, 4:13am UTC](https://forum.buildkite.community/t/how-do-you-write-and-execute-pre-or-post-command-script-in-buildkite/2054/1 "2022-05-26T04:13:48Z")

</div>

I am confuse with how to do it, Do i call script in a yaml file?

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [May 26, 2022, 4:21am UTC](https://forum.buildkite.community/t/how-do-you-write-and-execute-pre-or-post-command-script-in-buildkite/2054/2 "2022-05-26T04:21:29Z")

</div>

Hey @Joe,

`pre-command` and `post-command` are one of the hooks an agent runs in the context of running a job. The docs describe the purpose of each.

You have a few options on how to get them to execute for a job. The simplest option would be to write a [hook in your repository](https://buildkite.com/docs/agent/v3/hooks#hook-locations-repository-hooks). If you create an executable script in `.buildkite/hooks/pre-command`, the agent will find that and execute it at the pre-command stage of the job lifecycle. The same goes for `post-command` or any other hooks that can be read from the repository (the docs show which ones)

---

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [May 26, 2022, 4:24am UTC](https://forum.buildkite.community/t/how-do-you-write-and-execute-pre-or-post-command-script-in-buildkite/2054/3 "2022-05-26T04:24:04Z")

</div>

I see. Thank you,
