Return exit code 1 when builder type is not found
This commit is contained in:
parent
5e81c6f44e
commit
7466c4fdca
|
@ -115,6 +115,10 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, args []string) int {
|
|||
}
|
||||
|
||||
// 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)
|
||||
builds := make([]packer.Build, 0, len(buildNames))
|
||||
for _, n := range buildNames {
|
||||
|
@ -123,6 +127,7 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, args []string) int {
|
|||
c.Ui.Error(fmt.Sprintf(
|
||||
"Failed to initialize build '%s': %s",
|
||||
n, err))
|
||||
errors.m[n] = err
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -200,11 +205,6 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, args []string) int {
|
|||
sync.RWMutex
|
||||
m 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)
|
||||
for i := range builds {
|
||||
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
|
||||
func fileExists(filename string) bool {
|
||||
if _, err := os.Stat(filename); err == nil {
|
||||
|
@ -182,6 +206,9 @@ func testCoreConfigBuilder(t *testing.T) *packer.CoreConfig {
|
|||
if n == "file" {
|
||||
return &file.Builder{}, nil
|
||||
}
|
||||
if n == "non-existing" {
|
||||
return nil, fmt.Errorf("builder type not found")
|
||||
}
|
||||
return &null.Builder{}, nil
|
||||
},
|
||||
Provisioner: func(n string) (packer.Provisioner, error) {
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"builders": [
|
||||
{
|
||||
"name": "chocolate",
|
||||
"type": "file",
|
||||
"content": "chocolate",
|
||||
"target": "chocolate.txt"
|
||||
},
|
||||
{
|
||||
"name": "vanilla",
|
||||
"type": "non-existing",
|
||||
"content": "vanilla",
|
||||
"target": "vanilla.txt"
|
||||
}
|
||||
],
|
||||
"post-processors": [
|
||||
[
|
||||
{
|
||||
"name": "apple",
|
||||
"type": "shell-local",
|
||||
"inline": [
|
||||
"echo apple > apple.txt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "peach",
|
||||
"type": "shell-local",
|
||||
"inline": [
|
||||
"echo peach > peach.txt"
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"name": "pear",
|
||||
"type": "shell-local",
|
||||
"inline": [
|
||||
"echo pear > pear.txt"
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"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