Joey Armstrong | ed161f7 | 2023-04-11 13:16:59 -0400 | [diff] [blame] | 1 | #!/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 | // ----------------------------------------------------------------------- |
| 20 | def 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 | // ----------------------------------------------------------------------- |
| 30 | def 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 | |
| 40 | set -eu -o pipefail |
| 41 | umask 0 |
| 42 | |
| 43 | function error() |
| 44 | { |
| 45 | echo "** ${FUNCNAME[1]} ERROR: $*" |
| 46 | exit 1 |
| 47 | } |
| 48 | |
| 49 | dir="$WORKSPACE/bin" |
| 50 | if [ ! -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" |
| 56 | fi |
| 57 | |
| 58 | return |
| 59 | """) |
Joey Armstrong | ed161f7 | 2023-04-11 13:16:59 -0400 | [diff] [blame] | 60 | println("** ${iam}: LEAVE") |
| 61 | } |
| 62 | |
| 63 | // ----------------------------------------------------------------------- |
| 64 | // ----------------------------------------------------------------------- |
| 65 | Boolean call\ |
| 66 | ( |
Joey Armstrong | 41feb7c | 2023-04-14 11:28:04 -0400 | [diff] [blame] | 67 | // def self, // jenkins env object for access to primitives like echo() |
Joey Armstrong | ea63213 | 2023-04-13 13:09:23 -0400 | [diff] [blame] | 68 | Closure body // jenkins closure attached to the call iam() {closure} |
Joey Armstrong | ed161f7 | 2023-04-11 13:16:59 -0400 | [diff] [blame] | 69 | ) |
| 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] |