【发布时间】:2020-03-27 15:11:36
【问题描述】:
我有一个运行 kitchen converge 的 Jenkins 作业,但出现以下错误:
---- Begin output of /bin/systemctl restart docker ----
STDOUT:
STDERR: Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
---- End output of /bin/systemctl restart docker ----
我正在寻找一种方法来捕获上述两个命令的输出,以便诊断该环境中的说明书有什么问题。
在本地运行 kitchen converge 不会出错,并且我无权访问正在运行此作业的 Jenkins 节点。
我可以得到输出添加以下代码:
require 'mixlib/shellout'
Chef.event_handler do
on :run_failed do
systemctl = Mixlib::ShellOut.new("/bin/systemctl status docker.service")
systemctl.run_command
Chef::Log.info "Recipe failed miserably"
Chef::Log.info systemctl.stdout
Chef::Log.info systemctl.stderr
journalctl = Mixlib::ShellOut.new("/bin/journalctl -xe")
journalctl.run_command
Chef::Log.info journalctl.stdout
Chef::Log.info journalctl.stderr
end
end
这似乎不是最佳的。
【问题讨论】:
标签: docker jenkins chef-infra cookbook