Groovy web console

subscribe to the feed Subscribe
to this
site

Wrapping post build

Published 2 months ago by Josefk with tags jenkins
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
void run_with_post_step(Closure post_step, List post_step_parameters, Closure block) {
    println("Running main pipeline")
    try {
        block()
    } finally {
        println("Running post step")
        post_step(post_step_parameters)
    }
}

void my_teams_notification_post_step(String hook_url) {
    println("Would post to: ${hook_url}")
}

void my_customized_teams_notification_post_step(String hook_url, String special_information) {
    println("Would post to: ${hook_url}, including very special information: ${special_information}")
}

this.run_with_post_step(this.&my_teams_notification_post_step, ["https://this.is.my.channel.hook"]) {
    println("This is my first step of the pipeline!")
}

this.run_with_post_step(this.&my_customized_teams_notification_post_step, ["https://this.is.my.channel.hook", "This is HUNT speaking, we got a lot of issues."]) {
    println("This is my first step of the special pipeline!")
}

this.run_with_post_step(this.&my_teams_notification_post_step, ["https://this.is.my.channel.hook"]) {
    throw new Exception("Oh no, something went wrong!")
}