Using Alertra API with Jenkins Freestyle Projects
This will be for starting and stopping maintenance mode.
- In Jenkins go to Manage Jenkins > Manage Nodes, click on the node you will be using
- On the node page click Configure
- In the Node Properties section checkoff Environmental Variables
- Click Add
- Set the name to alertra_deviceID and value to your Alertra DeviceID
- Click Save at the bottom
- Create a new freestyle job
- In the General section check off "Restrict where this project can be run"
- In the label expression enter the name of the node you just edited
- In the Build Environment section check off Use secret text(s) or file(s)
- In the Bindings view that shows click Add, choose Secret text
- In the Secret text view that shows set the Variable to alertra_apikey
- Click add and select the Credentials Provider you would like to use (default is Jenkins)
- In the Jenkins Credentials Provider view that shows set the Kind to secret text
- Set the secret to your Alertra API key and the ID to alertra_apikey
- Click Add
- In the build steps section click "Add build step" and choose “HTTP Request”
- 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 - In the advanced section set the following parameters
Accept = APPLICATION_JSON
Content-type = TEXT_PLAIN - Add a custom header with the following parameters
Header = Alertra-API-Key
Value = ${alertra_apikey}
Mask value = checked - In the Body section set the following parameters
Request body = "{'Duration': '01:00'}"
This will set the device to maintenance mode for 1 hour - Run job and check Alertra
These steps can be reused for any API call for Alertra.