# Run a script during the build

> Add your own step before or after a phase of any build, with a script in the project's scripts folder.

Any build can run a script of yours before or after one of its phases, without writing a plugin.

## 1. Turn it on {#turn-on}

Add `BuildExtensionCommands` to the project's build-dependencies:

```conf file=plinto.conf
build-dependencies: {
  JavaBuild = 1.0
  Java = 25
  BuildExtensionCommands = 1.0
}
```

## 2. Add a script {#script}

Name it after the phase and when it runs: `scripts/before-<phase>.sh` or `scripts/after-<phase>.sh`.

| Phase | When |
|---|---|
| `prepare` | before anything is compiled |
| `compile` | compiling the code |
| `test` | running the tests (its scripts are skipped with the tests) |
| `package` | making the jar, wheel or archive |
| `release` | releasing, in `plinto release` only |

```text file=scripts/before-compile.sh
#!/bin/sh
echo "building $PLINTO_PROJECT $PLINTO_VERSION"
```

A script runs with its `#!` line, else with `sh`. Another name in `scripts/` that looks like a hook fails the build, with the names it takes.

## What a script gets {#environment}

| Variable | What it holds |
|---|---|
| `PLINTO_PROJECT`, `PLINTO_VERSION` | the project's name and version |
| `PLINTO_PROJECT_DIR`, `PLINTO_BUILD_DIR` | the project's folder and its `build/` |
| `PLINTO_HOOK` | which script this is, such as `before-compile` |
| `PLINTO_RELEASE`, `PLINTO_SKIP_TESTS` | whether it is a release, and whether tests are skipped |
| `PLINTO_OUTPUTS` | what the phases so far made, one file a line |

- [Your own scripts](../languages/custom.md): a whole build of your own
- [Build systems](../concepts/build-systems.md): the phases they run
- [Projects](../concepts/projects.md): build-dependencies
