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
8cb2fd76
Commit
8cb2fd76
authored
Jun 26, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/shell: Error if a script fails
parent
e5a7fc6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
14 deletions
+10
-14
provisioner/shell/provisioner.go
provisioner/shell/provisioner.go
+10
-14
No files found.
provisioner/shell/provisioner.go
View file @
8cb2fd76
...
...
@@ -100,7 +100,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
return
nil
}
func
(
p
*
Provisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
{
func
(
p
*
Provisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
error
{
scripts
:=
make
([]
string
,
len
(
p
.
config
.
Scripts
))
copy
(
scripts
,
p
.
config
.
Scripts
)
...
...
@@ -109,8 +109,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
if
p
.
config
.
Inline
!=
nil
{
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"packer-shell"
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error preparing shell script: %s"
,
err
))
return
return
fmt
.
Errorf
(
"Error preparing shell script: %s"
,
err
)
}
defer
os
.
Remove
(
tf
.
Name
())
...
...
@@ -121,14 +120,12 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
writer
:=
bufio
.
NewWriter
(
tf
)
for
_
,
command
:=
range
p
.
config
.
Inline
{
if
_
,
err
:=
writer
.
WriteString
(
command
+
"
\n
"
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error preparing shell script: %s"
,
err
))
return
return
fmt
.
Errorf
(
"Error preparing shell script: %s"
,
err
)
}
}
if
err
:=
writer
.
Flush
();
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error preparing shell script: %s"
,
err
))
return
return
fmt
.
Errorf
(
"Error preparing shell script: %s"
,
err
)
}
tf
.
Close
()
...
...
@@ -140,15 +137,13 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
log
.
Printf
(
"Opening %s for reading"
,
path
)
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error opening shell script: %s"
,
err
))
return
return
fmt
.
Errorf
(
"Error opening shell script: %s"
,
err
)
}
log
.
Printf
(
"Uploading %s => %s"
,
path
,
p
.
config
.
RemotePath
)
err
=
comm
.
Upload
(
p
.
config
.
RemotePath
,
f
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error uploading shell script: %s"
,
err
))
return
return
fmt
.
Errorf
(
"Error uploading shell script: %s"
,
err
)
}
// Compile the command
...
...
@@ -168,8 +163,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
log
.
Printf
(
"Executing command: %s"
,
cmd
.
Command
)
err
=
comm
.
Start
(
&
cmd
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Failed executing command: %s"
,
err
))
return
return
fmt
.
Errorf
(
"Failed executing command: %s"
,
err
)
}
exitChan
:=
make
(
chan
int
,
1
)
...
...
@@ -195,7 +189,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
log
.
Printf
(
"shell provisioner exited with status %d"
,
exitStatus
)
if
exitStatus
!=
0
{
ui
.
Error
(
fmt
.
Sprintf
(
"Script excited with non-zero exit status: %d"
,
exitStatus
)
)
return
fmt
.
Errorf
(
"Script exited with non-zero exit status: %d"
,
exitStatus
)
}
break
OutputLoop
...
...
@@ -212,4 +206,6 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
ui
.
Message
(
output
)
}
}
return
nil
}
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