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""" |
Joey Armstrong | 5d65efe | 2023-08-25 09:43:18 -0400 | [diff] [blame] | 39 | |
| 40 | print(""" |
| 41 | ** ----------------------------------------------------------------------- |
| 42 | ** Running: $cmd |
| 43 | ** ----------------------------------------------------------------------- |
| 44 | """) |
| 45 | |
Joey Armstrong | b9a6f12 | 2023-08-24 22:00:04 -0400 | [diff] [blame] | 46 | sh( |
| 47 | label : 'pkill_proc', // jenkins usability: label log entry 'step' |
| 48 | script : "${cmd}", |
| 49 | ) |
| 50 | |
| 51 | println("** ${iam}: LEAVE") |
| 52 | return(ans) |
| 53 | } |
| 54 | |
| 55 | // ----------------------------------------------------------------------- |
| 56 | // Install: Jenkins/groovy callback for installing the kind command. |
| 57 | // o Paramter branch is passed but not yet used. |
| 58 | // o Installer should be release friendly and checkout a frozen version |
| 59 | // ----------------------------------------------------------------------- |
| 60 | def call(String proc) { |
| 61 | String iam = getIam('main') |
| 62 | |
| 63 | println("** ${iam}: ENTER") |
| 64 | |
| 65 | try { |
| 66 | process(proc) |
| 67 | } |
| 68 | catch (Exception err) { |
| 69 | println("** ${iam}: EXCEPTION ${err}") |
| 70 | throw err |
| 71 | } |
| 72 | finally { |
| 73 | println("** ${iam}: LEAVE") |
| 74 | } |
| 75 | return |
| 76 | } |
| 77 | |
| 78 | // [EOF] |