Matteo Scandolo | 6784281 | 2021-07-13 16:52:13 -0700 | [diff] [blame] | 1 | // check if kail is installed, if not installs it |
| 2 | // and then uses it to collect logs on specified containers |
| 3 | |
| 4 | // appsToLog is a list of kubernetes labels used by kail to get the logs |
| 5 | // the generated log file is named with the string after = |
| 6 | // for example app=bbsim will generate a file called bbsim.log |
| 7 | |
| 8 | // to archive the logs use: archiveArtifacts artifacts: '${logsDir}/*.log' |
| 9 | def call(Map config) { |
| 10 | |
| 11 | def tagPrefix = "jenkins" |
| 12 | |
| 13 | def defaultConfig = [ |
| 14 | appsToLog: [ |
| 15 | 'app=onos-classic', |
| 16 | 'app=adapter-open-onu', |
| 17 | 'app=adapter-open-olt', |
| 18 | 'app=rw-core', |
| 19 | 'app=ofagent', |
| 20 | 'app=bbsim', |
| 21 | 'app=radius', |
| 22 | 'app=bbsim-sadis-server', |
| 23 | 'app=onos-config-loader', |
| 24 | ], |
| 25 | logsDir: "$WORKSPACE/logs" |
| 26 | ] |
| 27 | |
| 28 | if (!config) { |
| 29 | config = [:] |
| 30 | } |
| 31 | |
| 32 | def cfg = defaultConfig + config |
| 33 | |
| 34 | // check if kail is installed and if not installs it |
| 35 | sh """ |
| 36 | if ! command -v kail &> /dev/null |
| 37 | then |
| 38 | bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin" |
| 39 | fi |
| 40 | """ |
| 41 | |
| 42 | // fi the logsDir does not exists dir() will create it |
| 43 | dir(cfg.logsDir) { |
| 44 | for(int i = 0;i<cfg.appsToLog.size();i++) { |
| 45 | def label = cfg.appsToLog[i] |
| 46 | def logFile = label.split('=')[1] |
| 47 | def tag = "${tagPrefix}-kail-${logFile}" |
| 48 | println "Starting logging process for label: ${label}" |
| 49 | sh """ |
| 50 | _TAG=${tag} kail -l ${label} --since 1h > ${logsDir}/${logFile}.log& |
| 51 | """ |
| 52 | } |
| 53 | } |
| 54 | } |