Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
0b5f4d9d
Commit
0b5f4d9d
authored
Jul 15, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/shell: make build name and builder type env vars [GH-154]
parent
9387ba0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
CHANGELOG.md
CHANGELOG.md
+3
-0
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+14
-2
No files found.
CHANGELOG.md
View file @
0b5f4d9d
...
...
@@ -31,6 +31,9 @@ IMPROVEMENTS:
errors. [GH-104]
*
amazon-ebs: Credentials will come from IAM role if available. [GH-160]
*
amazon-ebs: Verify the source AMI is EBS-backed before launching. [GH-169]
*
shell provisioner: the build name and builder type are available in
the
`PACKER_BUILD_NAME`
and
`PACKER_BUILDER_TYPE`
env vars by default,
respectively. [GH-154]
*
vmware: error if shutdown command has non-zero exit status.
BUG FIXES:
...
...
provisioner/shell/provisioner.go
View file @
0b5f4d9d
...
...
@@ -47,6 +47,10 @@ type config struct {
// should be used to specify where the script goes, {{ .Vars }}
// can be used to inject the environment_vars into the environment.
ExecuteCommand
string
`mapstructure:"execute_command"`
// Packer configurations, these come from Packer itself
PackerBuildName
string
`mapstructure:"packer_build_name"`
PackerBuilderType
string
`mapstructure:"packer_builder_type"`
}
type
Provisioner
struct
{
...
...
@@ -139,7 +143,9 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
for
_
,
kv
:=
range
p
.
config
.
Vars
{
vs
:=
strings
.
Split
(
kv
,
"="
)
if
len
(
vs
)
!=
2
||
vs
[
0
]
==
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Environment variable not in format 'key=value': %s"
,
kv
))
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Environment variable not in format 'key=value': %s"
,
kv
))
}
}
...
...
@@ -182,6 +188,12 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
tf
.
Close
()
}
// Build our variables up by adding in the build name and builder type
envVars
:=
make
([]
string
,
len
(
p
.
config
.
Vars
)
+
2
)
envVars
[
0
]
=
"PACKER_BUILD_NAME="
+
p
.
config
.
PackerBuildName
envVars
[
1
]
=
"PACKER_BUILDER_TYPE="
+
p
.
config
.
PackerBuilderType
copy
(
envVars
[
2
:
],
p
.
config
.
Vars
)
for
_
,
path
:=
range
scripts
{
ui
.
Say
(
fmt
.
Sprintf
(
"Provisioning with shell script: %s"
,
path
))
...
...
@@ -202,7 +214,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
f
.
Close
()
// Flatten the environment variables
flattendVars
:=
strings
.
Join
(
p
.
config
.
Vars
,
" "
)
flattendVars
:=
strings
.
Join
(
env
Vars
,
" "
)
// Compile the command
var
command
bytes
.
Buffer
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment