blob: e22281b246ca74c3527bd9af7ff4b376059dd010 [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""")
Joey Armstronged161f72023-04-11 13:16:59 -040060 println("** ${iam}: LEAVE")
61}
62
63// -----------------------------------------------------------------------
64// -----------------------------------------------------------------------
65Boolean call\
66 (
Joey Armstrong41feb7c2023-04-14 11:28:04 -040067 // def self, // jenkins env object for access to primitives like echo()
Joey Armstrongea632132023-04-13 13:09:23 -040068 Closure body // jenkins closure attached to the call iam() {closure}
Joey Armstronged161f72023-04-11 13:16:59 -040069 )
70{
71 Map config = [:] // propogate block parameters
72 body.resolveStrategy = Closure.DELEGATE_FIRST
73 body.delegate = config // make parameters visible down below
74 body()
75
76 String iam = getIam('main')
77 println("** ${iam}: ENTER")
78 println("** ${iam}: Debug= is " + config.contains(debug))
79
80 try
81 {
82 process(config)
83 }
84 catch (Exception err)
85 {
86 println("** ${iam}: EXCEPTION ${err}")
87 throw err
88 }
89 finally
90 {
91 println("** ${iam}: LEAVE")
92 }
93 return
94}
95
96// [EOF]