# Build Stages

Gallery jobs are grouped into parallelizable stages. There are two types of stages, pre-infra (`init_stages`) and post-infra (`infra_stages`) stages, which have slightly different roles. Define these stages at the top of the `.gallery-deploy.yml` file:

```
init_stages:
    - build
infra_stages:
    - deploy
```

### Pre-Infrastructure Stages

Pre-infrastructure stages can be used to build code that will be used by the infrastructure deployment steps. For example, if you need to deploy a docker image to a managed instance group in a terraform file, you'll need to build the image in the pre-infrastructure stage.

### Post-Infrastructure Stages

Some providers don't have great support for deploying built code directly using terraform, and you may have to deploy artifacts on top of the infrastructure after it is created. You can use post-infrastructure stages to do this -- you'll have access to [environment variable mappers](/build-system/terraform/mapping-urls-configs.md#adding-environment-mappers) in these stages to give you information on the created infrastructure.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.usegallery.com/build-system/project-builds/build-stages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
