mirror of https://github.com/hashicorp/packer
hcl work on only/except (#9454)
* HCL2: allow to skip a named build block too * test that excepting a build block works * test only on a named build block * add/update docspull/9461/head
parent
b2320ca911
commit
fb337f8867
@ -0,0 +1,65 @@
|
||||
---
|
||||
layout: docs
|
||||
page_title: Only Except - HCL Configuration Language
|
||||
sidebar_title: Only Except
|
||||
description: >-
|
||||
Only and Except can be used as a command line argument to selectively run
|
||||
builds. Only and Except can also be used in a provisioner to not run it for a
|
||||
source.
|
||||
---
|
||||
|
||||
# Only and Except
|
||||
|
||||
`only` and `except` are keywords used to filter what runs in your Packer build,
|
||||
they can be seen as a command line argument:
|
||||
|
||||
`@include 'commands/except.mdx'`
|
||||
|
||||
`@include 'commands/only.mdx'`
|
||||
|
||||
They can also be seen in a template to run or skip provisioners and/or
|
||||
post-processors for a specific source:
|
||||
|
||||
```hcl
|
||||
build {
|
||||
name = "my_build"
|
||||
sources [
|
||||
"source.amazon-ebs.first-example",
|
||||
"source.amazon-ebs.second-example",
|
||||
]
|
||||
|
||||
provisioner "shell-local" {
|
||||
only = ["source.amazon-ebs.second-example"]
|
||||
inline = ["echo I will only run for the second example source"]
|
||||
}
|
||||
|
||||
provisioner "shell-local" {
|
||||
except = ["source.amazon-ebs.second-example"]
|
||||
inline = ["echo I will never run for the second example source"]
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
sources [
|
||||
"source.amazon-ebs.third-example",
|
||||
]
|
||||
}
|
||||
|
||||
# this file will result in Packer creating three builds named:
|
||||
# my_build.amazon-ebs.first-example
|
||||
# my_build.amazon-ebs.second-example
|
||||
# amazon-ebs.third-example
|
||||
```
|
||||
|
||||
Note that cli arguments can be used with a glob operator, using the previous
|
||||
configuration:
|
||||
|
||||
* `packer build -only 'my_build.*' dir`: will only run the builds in blocks
|
||||
named `my_build`.
|
||||
|
||||
* `packer build -only '*.amazon-ebs.*' dir`: will only run the builds with a
|
||||
source of type `amazon-ebs`.
|
||||
|
||||
-> Note: In the cli `only` and `except` will match agains **build names** (for
|
||||
example:`my_build.amazon-ebs.first-example`) but in a provisioner they will
|
||||
match on the **source type** (for example:`source.amazon-ebs.third-example`).
|
||||
@ -0,0 +1,7 @@
|
||||
- `-except=foo,bar,baz` - Run all the builds and post-processors except those
|
||||
with the given comma-separated names. Build and post-processor names by
|
||||
default are their type, unless a specific `name` attribute is specified
|
||||
within the configuration. Any post-processor following a skipped
|
||||
post-processor will not run. Because post-processors can be nested in
|
||||
arrays a different post-processor chain can still run. A post-processor
|
||||
with an empty name will be ignored.
|
||||
@ -0,0 +1,4 @@
|
||||
- `-only=foo,bar,baz` - Only run the builds with the given comma-separated
|
||||
names. Build names by default are their type, unless a specific `name`
|
||||
attribute is specified within the configuration. `-only` does not apply to
|
||||
post-processors.
|
||||
Loading…
Reference in new issue