In my current project we have 3 websites, two portals and an api. We just went through some major package upgrades, and unfortunately we didn’t notice our api site was not updated correctly. It was borked. HTTP 500 errors all over the place. And we deployed it to all test environments! Oh noes!

So once we got that fixed and all environments back up and running, it got me thinking what is the simplest and fastest test I could use to make sure the websites had been deployed correctly. Curl to the rescue! But since it was not installed on the Jenkins Build box, PowerShell would have to make do.

Create the following script file on your build box:

1
2
3
4
5
6
7
8
9
10
11
12
13
<#
Script to smoke test a website
#>
param(
	[ValidateNotNullOrEmpty()]
	[string]$Url = "https://www.coumnihan.co.za"
)

$StatusCode = ( Invoke-WebRequest -uri $Url -UseBasicParsing -UseDefaultCredentials | Select-Object StatusCode).StatusCode;
$value = $StatusCode -ne '200';
$global:LASTEXITCODE = $value;

exit $global:LASTEXITCODE;

If a request to load the page comes back with anything other than a HTTP 200, we can consider the website to be down, and will require further investigation.

We call this script from a Jenkins task like so:

Powershell.exe -ExecutionPolicy Bypass -NoProfile -WindowStyle Hidden -NonInteractive -File C:\DeploymentScripts\SmokeTestWebsite.ps1 -Url %MainWebsite%

Where the %MainWebsite% variable is passed in from the build or environment parameters.

And we’re done! A very simple “is my website up?” test completed and in use.