blob: 28d4f58f363269062aa8f3d9a77aefd4d12c9d8a [file] [log] [blame]
Joey Armstronged161f72023-04-11 13:16:59 -04001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
3// Copyright 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
18// -----------------------------------------------------------------------
19// -----------------------------------------------------------------------
20def getIam(String func)
21{
22 // Cannot rely on a stack trace due to jenkins manipulation
23 String src = 'vars/installKind.groovy'
24 String iam = [src, func].join('::')
25 return iam
26}
27
28// -----------------------------------------------------------------------
29// -----------------------------------------------------------------------
30def process(Map args) {
31
32 String iam = getIam('process')
33 println("** ${iam}: ENTER")
34
35 // go install sigs.k8s.io/kind@v0.18.0
36 sh(
37 returnStdout: true,
38 script: """#!/bin/bash
39
40set -eu -o pipefail
41umask 0
42
43function error()
44{
45 echo "** ${FUNCNAME[1]} ERROR: $*"
46 exit 1
47}
48
49dir="$WORKSPACE/bin"
50if [ ! -f "$dir/kind" ]; then
51 mkdir -p "$dir"
52 pushd "$dir" || error "pushd $dir failed"
53 curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.0/kind-linux-amd64
54 chmod +x ./kind
55 popd || error "popd $dir failed"
56fi
57
58return
59""")
60
61 println("** ${iam}: LEAVE")
62}
63
64// -----------------------------------------------------------------------
65// -----------------------------------------------------------------------
66Boolean call\
67 (
68 def self, // jenkins env object for access to primitives like echo()
69 Closure body, // jenkins closure attached to the call iam() {closure}
70 )
71{
72 Map config = [:] // propogate block parameters
73 body.resolveStrategy = Closure.DELEGATE_FIRST
74 body.delegate = config // make parameters visible down below
75 body()
76
77 String iam = getIam('main')
78 println("** ${iam}: ENTER")
79 println("** ${iam}: Debug= is " + config.contains(debug))
80
81 try
82 {
83 process(config)
84 }
85 catch (Exception err)
86 {
87 println("** ${iam}: EXCEPTION ${err}")
88 throw err
89 }
90 finally
91 {
92 println("** ${iam}: LEAVE")
93 }
94 return
95}
96
97// [EOF]