How to create web service health check using jenkins pipeline?

431 views
Skip to first unread message

fedora_user

unread,
Mar 31, 2022, 11:37:40 AM3/31/22
to Jenkins Users
Hi all,

New to jenkinsfile/groovy world. 

Can someone please let me know how to create a jenkins pipeline health check to check if multiple websites are running. 

If any of the sites are down or http response code is not 200 an email notification should be sent.

For every website to be checked should I create separate "stages" in the pipeline or is there a better way?

Thanks,
Misteek

Mark Waite

unread,
Mar 31, 2022, 11:52:04 AM3/31/22
to Jenkins Users
I think that what you're describing is a "test" to confirm the web sites are running.  One way to implement that is to create the web site checker as tests that output their results in JUnit format, then use the JUnit plugin to display the results in Jenkins.

That allows you to run the tests outside Jenkins and see multiple results inside Jenkins.

For example, you could write the test in Python and output the result to a junit format with as described https://stackoverflow.com/questions/11241781/python-unittests-in-jenkins

Another example, you could write the test in Javascript with jest, as described in https://stackoverflow.com/questions/54294612/how-to-publish-jest-test-results-in-jenkins

You could write the test in Java and output the result to junit format as done in the tutrorial https://www.jenkins.io/doc/tutorials/build-a-java-app-with-maven/#add-a-test-stage-to-your-pipeline

Each of those techniques have the benefit that you write the test locally, run it locally, then use Jenkins to execute the same test as you run locally.

Mark Waite

misteek

unread,
Mar 31, 2022, 9:06:39 PM3/31/22
to Jenkins Users
Hi Mark, 

Thanks for the details. Your suggestions sound good but bit too advanced for this newbie, I'm just getting my head around Jenkins Pipelines.

Was thinking something simpler to do a basic health check using curl to to check the URLs and return a 200 response code and if not successful to send an email.

Something along the lines of the pipeline example here:


or


Thanks
Misteek
Reply all
Reply to author
Forward
0 new messages