Commit fbb24d4a authored by Chris Bednarski's avatar Chris Bednarski

Changed interpolation logic so .BuildName can be used in the output config option

parent 8f2a9de2
...@@ -55,9 +55,12 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { ...@@ -55,9 +55,12 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
Interpolate: true, Interpolate: true,
InterpolateContext: &p.config.ctx, InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{ InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{}, Exclude: []string{"output"},
}, },
}, raws...) }, raws...)
if err != nil {
return err
}
errs := new(packer.MultiError) errs := new(packer.MultiError)
...@@ -67,16 +70,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { ...@@ -67,16 +70,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
} }
if p.config.OutputPath == "" { if p.config.OutputPath == "" {
p.config.OutputPath = "packer_{{.BuildName}}_{{.Provider}}" p.config.OutputPath = "packer_{{.BuildName}}_{{.BuilderType}}"
}
if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error parsing target template: %s", err))
}
templates := map[string]*string{
"output": &p.config.OutputPath,
} }
if p.config.CompressionLevel > pgzip.BestCompression { if p.config.CompressionLevel > pgzip.BestCompression {
...@@ -89,17 +83,9 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { ...@@ -89,17 +83,9 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
p.config.CompressionLevel = pgzip.DefaultCompression p.config.CompressionLevel = pgzip.DefaultCompression
} }
for key, ptr := range templates { if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil {
if *ptr == "" { errs = packer.MultiErrorAppend(
errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing target template: %s", err))
errs, fmt.Errorf("%s must be set", key))
}
*ptr, err = interpolate.Render(p.config.OutputPath, &p.config.ctx)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", key, err))
}
} }
p.config.detectFromFilename() p.config.detectFromFilename()
...@@ -113,7 +99,19 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { ...@@ -113,7 +99,19 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) { func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
target := p.config.OutputPath // These are extra variables that will be made available for interpolation.
p.config.ctx.Data = map[string]string{
"BuildName": p.config.PackerBuildName,
"BuilderType": p.config.PackerBuilderType,
}
target, err := interpolate.Render(p.config.OutputPath, &p.config.ctx)
if err != nil {
return nil, false, fmt.Errorf("Error interpolating output value: %s", err)
} else {
fmt.Println(target)
}
keep := p.config.KeepInputArtifact keep := p.config.KeepInputArtifact
newArtifact := &Artifact{Path: target} newArtifact := &Artifact{Path: target}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment