Using Alertra API with Jenkins Freestyle Projects

This will be for starting and stopping maintenance mode.

  1. In Jenkins go to Manage Jenkins > Manage Nodes, click on the node you will be using
  2. On the node page click Configure
  3. In the Node Properties section checkoff Environmental Variables
  4. Click Add
  5. Set the name to alertra_deviceID and value to your Alertra DeviceID
  6. Image Showing Node Properties to Alertra DeviceID
  7. Click Save at the bottom
  8. Create a new freestyle job
  9. In the General section check off "Restrict where this project can be run"
  10. In the label expression enter the name of the node you just edited
  11. Image Showing Label Expression Field for Alertra
  12. In the Build Environment section check off Use secret text(s) or file(s)
  13. In the Bindings view that shows click Add, choose Secret text
  14. In the Secret text view that shows set the Variable to alertra_apikey
  15. Click add and select the Credentials Provider you would like to use (default is Jenkins)
  16. In the Jenkins Credentials Provider view that shows set the Kind to secret text
  17. Set the secret to your Alertra API key and the ID to alertra_apikey
  18. Click Add
  19. Image Showing Jenkins Credentials Provider - Add Credentials for Alertra
  20. In the build steps section click "Add build step" and choose “HTTP Request”
  21. Set the following parameter
    URL = [https://api.alertra.com/v1.1/devices/${alertra_deviceID}/start-maintenance](https://api.alertra.com/v1.1/devices/${alertra_deviceID}/start-maintenance
    HTTP mode = PUT
    Ignore Ssl errors = No
  22. In the advanced section set the following parameters
    Accept = APPLICATION_JSON
    Content-type = TEXT_PLAIN
  23. Add a custom header with the following parameters
    Header = Alertra-API-Key
    Value = ${alertra_apikey}
    Mask value = checked
  24. In the Body section set the following parameters
    Request body = "{'Duration': '01:00'}"
    This will set the device to maintenance mode for 1 hour
  25. Run job and check Alertra

These steps can be reused for any API call for Alertra.