---
description: |
  The `build` block contains instructions for Packer to follow during a build. Learn how to configure the `build` block in your Packer templates.
page_title: build block reference
---

# `build` block

This topic provides reference information about the `build` block.


## Description 

The `build` block specifies which builders Packer should run, how to provision them,
and any post-processing actions Packer should perform on the resulting artifacts.

To use builders in a `build` block you can either:

- Set the `sources` array of string with references to pre-defined sources.

- Define [build-level `source` blocks](/packer/docs/templates/hcl_templates/blocks/build/source).
  This also allows you to set specific fields.

`@include 'from-1.5/builds/example-block.mdx'`

Define [top-level `source` blocks](/packer/docs/templates/hcl_templates/blocks/source) to configure
your builders. The list of available builders can be found in the
[builders](/packer/docs/builders) section.

## Naming your builds

The optional `name` field of the `build` block can be used to set the name of a
build. Named builds will prefix the log lines in a `packer build` with the name
of the build block. For example:

```hcl
source "null" "first-example" {
    communicator = "none"
}

source "null" "second-example" {
    communicator = "none"
}

build {
    name = "a"

    sources = [
        "sources.null.first-example",
        "sources.null.second-example",
    ]
}


build {
    sources = ["sources.null.second-example"]
}
```

Will output:

```shell-session
> packer build ./folder
Build 'a.null.first-example' finished.
Build 'a.null.second-example' finished.
Build 'null.second-example' finished.

==> Builds finished. The artifacts of successful builds are:
--> a.null.first-example: Did not export anything. This is the null builder
--> a.null.second-example: Did not export anything. This is the null builder
--> null.second-example: Did not export anything. This is the null builder
```

### Running only specific builds

The `-only`/`-except` flags will match a source's `type.name` and run 'only'
matching **builders** (source) or all referenced builders 'except' the matching
ones, for example with the same config file:

```shell-session
> packer build -only "*.second-example" ./folder
Build 'null.second-example' finished.
Build 'a.null.second-example' finished.

==> Builds finished. The artifacts of successful builds are:
--> a.null.second-example: Did not export anything. This is the null builder
--> null.second-example: Did not export anything. This is the null builder
```

Here `'a.null.first-example'` was skipped.

-> Note: It is not yet possible to match a named `build` block to do this, but
this is soon going to be possible. So here "a.\*" will match nothing.

## Related

- A list of [community
  builders](https://packer.io/community-tools#community-builders) is available.

- Create your own [custom builder](/packer/docs/plugins/creation/custom-builders) !
