import java.net.URLConnection

def prefix = "UBXLIB_POWER_SWITCH_"

// Where the environment variable UBXLIB_POWER_SWITCH_x_ON or UBXLIB_POWER_SWITCH_x_OFF
// exists, expected to be a HTTP string that will switch on or off switch x, do that thing.
node () {
    for (int x = 0; x < 10; x++) {
        name = prefix + x as String
        if (params.ON_NOT_OFF) {
            name += "_ON"
        } else {
            name += "_OFF"
        }
        command = env[name]
        if (command) {
            stage(name) {
                def httpRequest = new URL(command)
                def httpResponse = httpRequest.openConnection().getResponseCode()
                println "${name} [${command}] returned HTTP response ${httpResponse}."
            }
        }
    }
}