Home > other >  Windows batch command to get the Jenkins Selenium Grid status
Windows batch command to get the Jenkins Selenium Grid status

Time:05-01

I want to execute the tests in Selenium Grid using Jenkins and before running the tests, I want to ensure that Selenium grid is up and ready by using the curl and jq command in Windows batch.

I tried running the below command:

curl http://localhost:4444/wd/hub/status

Below is the sample of the entire output:

{
  "value": {
    "ready": true,
    "message": "Selenium Grid ready.",
    "nodes": [
      {
        "id": "5150c3b9-9bc2-45ad-9605-21c1c4ed90e4",
        "uri": "http:\u002f\u002f172.27.0.3:5555",
        "maxSessions": 4,
        "osInfo": {
          "arch": "amd64",
          "name": "Linux",
          "version": "5.10.16.3-microsoft-standard-WSL2"
        },
        "heartbeatPeriod": 60000,
        "availability": "UP",
        "version": "4.1.3 (revision 7b1ebf28ef)",

Now I want to get the value of the ready and the message object from the above response and loop it until the value of ready is true.

Can anyone please help here ?

CodePudding user response:

I would use a simple batch script to check if Jenkins is started.

@echo off

set checks=3

:again
jenkins.exe status | find "Started" >nul
if errorlevel 1 (
   timeout /t 1 1>nul
   echo %checks%
   set /a checks=checks-1
   if not "%checks%"=="0" goto :again
   goto :error
)

echo Jenkins is started
goto :eof

:error
echo Jenkins is NOT started

EDIT: Checking for message can be done in mostly the same way as above where "Started" is checked.

type jenkins.json | jq -r ".value.message" | find "Selenium Grid ready."

After this the errorlevel will be 1 when the text "Selenium Grid ready." is not found, and 0 when it is found.

  • Related