Merge pull request #8475 from hashicorp/fix_8472
Return exit code 1 when builder type is not found
This commit is contained in:
commit
8073a5381c
|
@ -115,6 +115,10 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the builds we care about
|
// Get the builds we care about
|
||||||
|
var errors = struct {
|
||||||
|
sync.RWMutex
|
||||||
|
m map[string]error
|
||||||
|
}{m: make(map[string]error)}
|
||||||
buildNames := c.Meta.BuildNames(core)
|
buildNames := c.Meta.BuildNames(core)
|
||||||
builds := make([]packer.Build, 0, len(buildNames))
|
builds := make([]packer.Build, 0, len(buildNames))
|
||||||
for _, n := range buildNames {
|
for _, n := range buildNames {
|
||||||
|
@ -123,6 +127,7 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, args []string) int {
|
||||||
c.Ui.Error(fmt.Sprintf(
|
c.Ui.Error(fmt.Sprintf(
|
||||||
"Failed to initialize build '%s': %s",
|
"Failed to initialize build '%s': %s",
|
||||||
n, err))
|
n, err))
|
||||||
|
errors.m[n] = err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,11 +205,6 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, args []string) int {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
m map[string][]packer.Artifact
|
m map[string][]packer.Artifact
|
||||||
}{m: make(map[string][]packer.Artifact)}
|
}{m: make(map[string][]packer.Artifact)}
|
||||||
var errors = struct {
|
|
||||||
sync.RWMutex
|
|
||||||
m map[string]error
|
|
||||||
}{m: make(map[string]error)}
|
|
||||||
|
|
||||||
limitParallel := semaphore.NewWeighted(cfg.ParallelBuilds)
|
limitParallel := semaphore.NewWeighted(cfg.ParallelBuilds)
|
||||||
for i := range builds {
|
for i := range builds {
|
||||||
if err := buildCtx.Err(); err != nil {
|
if err := buildCtx.Err(); err != nil {
|
||||||
|
|
|
@ -166,6 +166,30 @@ func TestBuildExceptFileCommaFlags(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildExceptNonExistingBuilder(t *testing.T) {
|
||||||
|
c := &BuildCommand{
|
||||||
|
Meta: testMetaFile(t),
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{
|
||||||
|
"-parallel=false",
|
||||||
|
`-except=`,
|
||||||
|
filepath.Join(testFixture("build-only"), "not-found.json"),
|
||||||
|
}
|
||||||
|
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
if code := c.Run(args); code != 1 {
|
||||||
|
t.Errorf("Expected to find exit code 1, found %d", code)
|
||||||
|
}
|
||||||
|
if !fileExists("chocolate.txt") {
|
||||||
|
t.Errorf("Expected to find chocolate.txt")
|
||||||
|
}
|
||||||
|
if fileExists("vanilla.txt") {
|
||||||
|
t.Errorf("NOT expected to find vanilla.tx")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fileExists returns true if the filename is found
|
// fileExists returns true if the filename is found
|
||||||
func fileExists(filename string) bool {
|
func fileExists(filename string) bool {
|
||||||
if _, err := os.Stat(filename); err == nil {
|
if _, err := os.Stat(filename); err == nil {
|
||||||
|
@ -182,6 +206,9 @@ func testCoreConfigBuilder(t *testing.T) *packer.CoreConfig {
|
||||||
if n == "file" {
|
if n == "file" {
|
||||||
return &file.Builder{}, nil
|
return &file.Builder{}, nil
|
||||||
}
|
}
|
||||||
|
if n == "non-existing" {
|
||||||
|
return nil, fmt.Errorf("builder type not found")
|
||||||
|
}
|
||||||
return &null.Builder{}, nil
|
return &null.Builder{}, nil
|
||||||
},
|
},
|
||||||
Provisioner: func(n string) (packer.Provisioner, error) {
|
Provisioner: func(n string) (packer.Provisioner, error) {
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"builders": [
|
||||||
|
{
|
||||||
|
"name": "chocolate",
|
||||||
|
"type": "file",
|
||||||
|
"content": "chocolate",
|
||||||
|
"target": "chocolate.txt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vanilla",
|
||||||
|
"type": "non-existing",
|
||||||
|
"content": "vanilla",
|
||||||
|
"target": "vanilla.txt"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"post-processors": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"only": [
|
||||||
|
"vanilla"
|
||||||
|
],
|
||||||
|
"name": "tomato",
|
||||||
|
"type": "shell-local",
|
||||||
|
"inline": [
|
||||||
|
"echo tomato > tomato.txt"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"only": [
|
||||||
|
"chocolate"
|
||||||
|
],
|
||||||
|
"type": "shell-local",
|
||||||
|
"inline": [
|
||||||
|
"echo unnamed > unnamed.txt"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue