blob: e7cc57af497a6164a19e4707f32515cb069dbb60 [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"
Joey Armstronge5aae1c2023-07-24 14:11:20 -040050cmd="$dir/kind"
51if [ ! -f "$cmd" ]; then
Joey Armstronged161f72023-04-11 13:16:59 -040052 mkdir -p "$dir"
53 pushd "$dir" || error "pushd $dir failed"
54 curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.0/kind-linux-amd64
55 chmod +x ./kind
56 popd || error "popd $dir failed"
57fi
58
Joey Armstronge5aae1c2023-07-24 14:11:20 -040059## Sanity check installed binary
60echo
61echo "Kind command verison: $("$cmd" --version)"
62
Joey Armstronged161f72023-04-11 13:16:59 -040063return
64""")
Joey Armstronged161f72023-04-11 13:16:59 -040065 println("** ${iam}: LEAVE")
66}
67
68// -----------------------------------------------------------------------
69// -----------------------------------------------------------------------
70Boolean call\
71 (
Joey Armstrong41feb7c2023-04-14 11:28:04 -040072 // def self, // jenkins env object for access to primitives like echo()
Joey Armstrongea632132023-04-13 13:09:23 -040073 Closure body // jenkins closure attached to the call iam() {closure}
Joey Armstronged161f72023-04-11 13:16:59 -040074 )
75{
76 Map config = [:] // propogate block parameters
77 body.resolveStrategy = Closure.DELEGATE_FIRST
78 body.delegate = config // make parameters visible down below
79 body()
80
81 String iam = getIam('main')
82 println("** ${iam}: ENTER")
83 println("** ${iam}: Debug= is " + config.contains(debug))
84
85 try
86 {
87 process(config)
88 }
89 catch (Exception err)
90 {
91 println("** ${iam}: EXCEPTION ${err}")
92 throw err
93 }
94 finally
95 {
96 println("** ${iam}: LEAVE")
97 }
98 return
99}
100
101// [EOF]