Save curl Response in a varaible in Jenkins declarative pipeline

Viewed 8

I have a Jenkins decalarative pipeline where I am calling some URL via cURL which is returning JSON response. How to catch that JSON in a variable?

Have tried the below code but it's returning entire thing with path and command along with the response

environment {
        token = bat(returnStdout: true, script: 'curl https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d "{\\"username\\" : \\"user\\",\\"password\\" : \\"pwd\\"}"').trim()
        }
0 Answers
Related