将cURL响应保存在Jenkins声明性管道中的变量中

t5fffqht  于 2022-10-06  发布在  Jenkins
关注(0)|答案(0)|浏览(87)

我有一个Jenkins deararative管道,其中我通过cURL调用一些URL,该URL返回JSON响应。如何在变量中捕获该JSON?

我尝试了下面的代码,但它返回的是带有路径和命令的全部内容以及响应

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

JSON响应

C:ProgramDataJenkins.jenkinsworkspacepublish-api>curl https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d "{"username" : "ap-1","password" : "Ap5"}" 
{
  "access_token": "axxxx-5ca2-48eb-9eb3-173c44a811",
  "token_type": "bearer",
  "redirectUrl": "/home/"
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题