On Thu, Feb 18, 2021 at 09:07:40AM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 100 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 10 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..f31771e5c 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,95 @@ #!/usr/bin/env ruby
+require 'json'
while (line = STDIN.gets)
- case line.chomp!
- when /ok=(\d+)\s+changed=(\d+)\s+unreachable=(\d+)\s+failed=(\d+)\s+skipped=(\d+)\s+rescued=(\d+)\s+ignored=(\d+)/
- puts "ansible_test.total.nr_ok: #{$1}"
- puts "ansible_test.total.nr_changed: #{$2}"
- puts "ansible_test.total.nr_failed: #{$4}"
- puts "ansible_test.total.nr_skipped: #{$5}"
- puts "ansible_test.total.nr_rescued: #{$6}"
- puts "ansible_test.total.nr_ignored: #{$7}"
- when /playbook_run_on_fail/
- puts line
- line = line.gsub(/'/, ' ')
- ansible_stats_error = `echo '#{line}' |grep -E 'FAILED! |failed: .*}$' | awk -F'=>' '{$1="";print $0}'`
- next if ansible_stats_error.empty?
- a = JSON.load(ansible_stats_error)
- unless a['msg'].nil?
保持原来的 case line .. when ... 代码会更好。 line从msg里来。
Thanks, Fengguang