【问题标题】:How to capture `systemctl status` and `journalctl -xe` from a kitchen run inside a Jenkins job如何从 Jenkins 作业中运行的厨房捕获“systemctl status”和“journalctl -xe”
【发布时间】: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


    【解决方案1】:

    您没有指定执行上述命令的主厨资源,但一般来说 - 使用 debug log level 执行主厨客户端:

    $ chef-client --log_level debug
    

    您可以通过设置log level in kitchen provisioner来实现它

    ---
    provisioner:
      name: chef_zero
      log_level: :debug
    

    【讨论】:

      猜你喜欢
      • 2016-09-04
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 2015-12-31
      • 2018-08-25
      相关资源
      最近更新 更多