Joey Armstrong | b9a6f12 | 2023-08-24 22:00:04 -0400 | [diff] [blame^] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
| 3 | // Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | // ----------------------------------------------------------------------- |
| 17 | // Install the voltctl command by branch name "voltha-xx" |
| 18 | // ----------------------------------------------------------------------- |
| 19 | |
| 20 | // ----------------------------------------------------------------------- |
| 21 | // ----------------------------------------------------------------------- |
| 22 | String getIam(String func) { |
| 23 | // Cannot rely on a stack trace due to jenkins manipulation |
| 24 | String src = 'vars/pkill_proc.groovy' |
| 25 | String iam = [src, func].join('::') |
| 26 | return iam |
| 27 | } |
| 28 | |
| 29 | // ----------------------------------------------------------------------- |
| 30 | // ----------------------------------------------------------------------- |
| 31 | Boolean process(String proc) { |
| 32 | String iam = getIam('process') |
| 33 | Boolean ans = true |
| 34 | |
| 35 | println("** ${iam}: ENTER") |
| 36 | |
| 37 | String cmdKill = "pkill --echo '${proc}'" |
| 38 | String cmd = """if [[ \$(pgrep --count "${proc}") -gt 0 ]]; then ${cmdKill}; fi""" |
| 39 | println(" ** Running: ${cmd}") |
| 40 | sh( |
| 41 | label : 'pkill_proc', // jenkins usability: label log entry 'step' |
| 42 | script : "${cmd}", |
| 43 | ) |
| 44 | |
| 45 | println("** ${iam}: LEAVE") |
| 46 | return(ans) |
| 47 | } |
| 48 | |
| 49 | // ----------------------------------------------------------------------- |
| 50 | // Install: Jenkins/groovy callback for installing the kind command. |
| 51 | // o Paramter branch is passed but not yet used. |
| 52 | // o Installer should be release friendly and checkout a frozen version |
| 53 | // ----------------------------------------------------------------------- |
| 54 | def call(String proc) { |
| 55 | String iam = getIam('main') |
| 56 | |
| 57 | println("** ${iam}: ENTER") |
| 58 | |
| 59 | try { |
| 60 | process(proc) |
| 61 | } |
| 62 | catch (Exception err) { |
| 63 | println("** ${iam}: EXCEPTION ${err}") |
| 64 | throw err |
| 65 | } |
| 66 | finally { |
| 67 | println("** ${iam}: LEAVE") |
| 68 | } |
| 69 | return |
| 70 | } |
| 71 | |
| 72 | // [EOF] |