Add option for docker executor to handle stderr from results

Instead of always joining stdout and stderr, only join the two if the
caller explicitly asks for it. Otherwise, only return stdout.
This commit is contained in:
Brian Cain 2019-11-22 12:04:09 -08:00
parent 1699821571
commit 2901dae948
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 10 additions and 7 deletions

View File

@ -20,9 +20,10 @@ module VagrantPlugins
# #
# @return [String] id - ID matched from the docker build output. # @return [String] id - ID matched from the docker build output.
def build(dir, **opts, &block) def build(dir, **opts, &block)
args = Array(opts[:extra_args]) args = Array(opts[:extra_args])
args << dir args << dir
result = execute('docker', 'build', *args, &block) opts = {with_stderr: true}
result = execute('docker', 'build', *args, opts, &block)
matches = result.match(/Successfully built (?<id>.+)$/i) matches = result.match(/Successfully built (?<id>.+)$/i)
if !matches if !matches
# Check for the new output format 'writing image sha256...' # Check for the new output format 'writing image sha256...'

View File

@ -27,10 +27,12 @@ module VagrantPlugins
stdout: result.stdout stdout: result.stdout
end end
if result.stdout.to_s.strip.length == 0 if opts
result.stderr if opts[:with_stderr]
else return result.stdout + " " + result.stderr
result.stdout else
return result.stdout
end
end end
end end