Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Created January 18, 2020 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThabetAmer/a0bda358d66503b3f8cf1e343460202a to your computer and use it in GitHub Desktop.
Save ThabetAmer/a0bda358d66503b3f8cf1e343460202a to your computer and use it in GitHub Desktop.
Jenkins Groovy function to check URL availability
#!/usr/bin/env groovy
/**
* Checks URL availability via curl
* @author thabet.amer@gmail.com
* @since Jenkins 2.204.1
* @param String url
* @return String Zero if succeeded, error if not.
*
*/
def curlstatus(String url) {
assert url != null
int status = sh(label: 'Check URL',
returnStdout: true,
script: "curl -sLI -w '%{http_code}' ${url} -o /dev/null"
)
if (status != 200) {
return "Returned status code = ${status} when calling ${url}"
}
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment