blob: 1ad5dfc2ddb5cd06d0895f49d64d4f8cd67ca062 [file] [log] [blame]
Joey Armstrongb9a6f122023-08-24 22:00:04 -04001#!/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// -----------------------------------------------------------------------
22String getIam(String func) {
23 // Cannot rely on a stack trace due to jenkins manipulation
24 String src = 'vars/pgrep_proc.groovy'
25 String iam = [src, func].join('::')
26 return iam
27}
28
29// -----------------------------------------------------------------------
30// -----------------------------------------------------------------------
31Boolean process(String proc) {
32 String iam = getIam('process')
33 Boolean ans = true
34
35 println("** ${iam}: ENTER")
36
37 String cmdFull = "pgrep --list-full '${proc}'"
38 String cmd = """if [[ \$(pgrep --count "${proc}") -gt 0 ]]; then ${cmdFull}; fi"""
39
Joey Armstrong5d65efe2023-08-25 09:43:18 -040040 print("""
41** -----------------------------------------------------------------------
42** Running: $cmd
43** -----------------------------------------------------------------------
44""")
Joey Armstrongb9a6f122023-08-24 22:00:04 -040045 sh(
46 label : 'pgrep_proc', // jenkins usability: label log entry 'step'
47 script : "${cmd}",
48 )
49
50 println("** ${iam}: LEAVE")
51 return(ans)
52}
53
54// -----------------------------------------------------------------------
55// Install: Jenkins/groovy callback for installing the kind command.
56// o Paramter branch is passed but not yet used.
57// o Installer should be release friendly and checkout a frozen version
58// -----------------------------------------------------------------------
59def call(String proc) {
60 String iam = getIam('main')
61
62 println("** ${iam}: ENTER")
63
64 try {
65 process(proc)
66 }
67 catch (Exception err) {
68 println("** ${iam}: EXCEPTION ${err}")
69 throw err
70 }
71 finally {
72 println("** ${iam}: LEAVE")
73 }
74 return
75}
76
77// [EOF]