I am setting up a proof of concept to monitor the status of some Azure DevOps build agents by executing the below Azure DevOps API command in Postman.
I'm then extracting the Name
and Hosted
status of each agent using the below Postman commands, with the resultant output then getting set as Postman Collection variables, as depicted in the image further below.
let jsonData = pm.response.json().value
jsonData.forEach((item, index) => {
pm.collectionVariables.set(item["name"], item["isHosted"])
})
Finally, what I then seek to do is POST the entire set of Collection variables to an instant messaging service such as Flock (or even Slack), using a custom webhook in Postman. I have successfully managed to set up this custom webhook using another Postman API command which is depicted below.
However, as also shown above, I'm only ever able to successfully POST the agent status to Flock one at a time, by commenting out all but one agent reference. I need to be able to:
- Send the entire set of Agent status value to Flock in one go.
- Not be required to explicitly enter the name of each Collection variable to obtain its corresponding value.
Any suggestions on how I can achieve this?
Based on your requirement, I suggest that you can consider adding the postman.setNextRequest() to your foreach script to send requests multiple times in one run.
Here are the steps:
Step1: Create Get Pools request and Post Flock request in the Postman collection.
Step2: Add the following script sample in the Get Pools request:
This step will set two variables: the pool name based on the agent pool name and set the expected pool name and ishosted value.
Step3: Use the variable in the Post Flock request.
For example:
{{name}} represent the agent Pool name. {{{{name}}}} represent the ishosted value of hte Agent Pool.
Step4: You can use the Collection Runner to run the script.
For more detailed info, you can refer to this doc: Customize request order in a collection run