You should start with looking at the URL class. http://docs.groovy-lang.org/latest/html/groovy-jdk/java/net/URL.html
That will allow you to read the whole page under a certain URL using getText()
. If the page is down, this will throw an exception.
Jenkins should then automatically fail the job. In the Jenkins job definition, you can specify when and how to send a Mail.
EDIT This isn't valid Groovy: (curl -Is https://google.com | head -1)
. Groovy can't run shell commands or build pipes with |
like BASH does. Also, you have to use {}
around the then/else blocks after the if, not ()
. Lastly, there is no fi
in Groovy:
if (condition) {
...then...
} else {
...
}
See Groovy executing shell commands for how to run shell commands from Groovy scripts.
Not that you have to examine the result of exitValue()
to determine whether the command failed. 0
is success.