简体   繁体   English

如何在 Groovy 中使用 JSL 的多个输入值来制作循环函数

[英]How to make loop function using multiple input value to JSL in Groovy

I'm using the below function in Jenkins Shared Library.我在 Jenkins 共享库中使用以下函数。

/* The below function delete uploads that exist in the server. */

 

def delete_upload(server_url,each_upload_id,authentication){

 

    def delete_upload_url  = server_url + "/api/v1/uploads/" + each_upload_id

  

    def response =  httpRequest consoleLogResponseBody: true,

                    contentType: 'APPLICATION_JSON',

                    customHeaders: [[maskValue: false, name: 'id ', value: each_upload_id],

                    [maskValue: false, name: 'Authorization', value: authentication]],

                    httpMode: 'DELETE', ignoreSslErrors: true, responseHandle: 'NONE', url: delete_upload_url,

                    validResponseCodes: '100:599'

  

    if(response.status == 202){

    def result = readJSON text: """${response.content}"""

    return result['message'].toString()

    }

    else {

        throw new Exception("Incorrect upload id! Please give the correct upload id.")

    }

}

==================================================================================================== ================================================ ================================================

I'm getting below response ,我得到低于响应

Response Code: HTTP/1.1 202 Accepted Response: {"code":202,"message":"Delete Job for file with id 2","type":"INFO"} Success: Status code 202 is in the accepted range: 100:599响应代码:HTTP/1.1 202 接受的响应:{"code":202,"message":"Delete Job for file with id 2","type":"INFO"} 成功:状态代码 202 在可接受的范围内: 100:599

==================================================================================================== ================================================ ================================================

Purpose : I'm using the above JSL function to delete a uploads in the web server using upload id.目的:我正在使用上述 JSL 函数使用上传 ID 删除 Web 服务器中的上传。

Requirement :要求

I need to delete multiple uploads by using multiple upload id's (like each_upload_id in 1,2,3 etc) using this JSL delete function.我需要使用此 JSL 删除功能通过使用多个上传 ID(如 1、2、3 中的 each_upload_id 等)来删除多个上传。

Need to pass the upload id's in loops and delete the uploads in the web server.需要在循环中传递上传 ID 并删除 Web 服务器中的上传。

Any suggestions, please?有什么建议吗?

Are you looking for something like this?你在找这样的东西吗?

def idList = ["1", "2", "3"]

try {
   idList.each{ id =>
     delete_upload(server_url,id,authentication)
   }
} catch(e) {
println "Error occurred!"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM