Creating a loop function in Groovy that accepts multiple input values and passes them to JSL

I have implemented the following function within a Jenkins Shared Library.

/* This function is designed to delete uploads that are stored on 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 provide the correct upload id.")

    }

}

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

After making use of the above function,

Response Code: HTTP/1.1 202 Accepted Response: {"code":202,"message":"Delete Job for file with id 2","type":"INFO"} Success: Status code 202 indicates acceptance within the range of 100:599

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

Purpose: The intention behind using the aforementioned JSL function is to remove uploads from a web server utilizing their upload ids.

Requirement:

I am looking to delete multiple uploads by supplying various upload ids (such as each_upload_id being 1, 2, 3 etc) using the provided JSL delete function.

The goal is to iterate through the upload ids and delete the corresponding uploads on the web server.

If you have any suggestions, please share them.

Answer №1

Have you been searching for a solution along these lines?

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

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for stopping PHP echo from cutting off a JS string?

I encountered an issue with my code: <!DOCTYPE html> <html> <head> <title>Sign up page</title> <meta charset="UTF-8"/> </head> <body> <h1>Sign up page</h ...

Serve static files using ExpressJS when a post request is made

My Express server is set up to serve static files for my website and it's working fine: var express = require('express'); var app = express(); var path = require('path'); var p = path.join(__dirname, '../web/public'); app ...

Tips for resolving the 'node is not defined' error in the case of passing a default value

Attempting to incorporate the Trie data structure into JavaScript has presented a challenge. Within the print function, which displays an array of all words in the Trie, there is a search function that looks for words within the Trie and adds them to the a ...

Child node in Firebase successfully deleted

Is there a method to determine if a subchild has been removed from the database structure below: users:{ a: { friends: { b:Jhon, c:Ted }, b: { friends: { a: Tom } }, c: { friends:{ a: Tom } } } I a ...

What is the best way to create a generic variable and function that utilize the same type?

I am looking for a structure similar to interface propType { value: T action: (value: T) => void } The variable T can be any type, but it must be consistent for both value and action. Using any is not suitable as it could lead to a mismatch in ty ...

Is there a way to add an entire array of child nodes to a parent node in a single operation using JavaScript?

Is there a quick way in JavaScript to attach an array of child nodes to a parent node all at once? I'm looking for a method that will avoid triggering unnecessary repaints. So far, I attempted using parent.appendChild(arrayOfNodes), but it resulted ...

Using TypeScript, we can assign a JSON object to an extended class by leveraging the

Task was to include an additional property. I modified a current class by adding a new property, but when I assign a JSON object from the database, the newly added property disappears. Is there a way to correctly assign a JSON object to a TypeScript class ...

The ng-model-options in Angular 2 is set to "updateOn: 'change blur'"

Currently working with angular 2, I am seeking a solution to modify the behavior of ngModel upon Enter key press. In angular 1.X, we utilized ng-model-options="{updateOn: 'change blur'}". How can this be achieved in angular 2? For reference, her ...

Can anyone share best practices for writing unit tests for $scope.broadcast and $scope.$on in Jasmine?

Greetings, I am new to the AngularJs/NodeJs realm, so please bear with me if this question seems basic to some. Essentially, I have two controllers where the first controller broadcasts an 'Id' and the second controller retrieves that Id using $ ...

What is the best way to develop a card stack swiper similar to Tinder using React?

After experimenting with various packages, I found that none were satisfactory for creating a customizable card swiper. As a result, I am now considering developing my own solution. What would be the best approach for adding animations, enabling draggable ...

Choose the item to automatically reposition itself below once it has been opened

issue : The current behavior is that when the "other" option is selected, the input field appears. However, if I click on the select again, it covers up the input field. desired outcome : Ideally, I want the input field to show up when the "other" option ...

A jquery class for styling with CSS

I am looking to add a CSS class to a gridview. I attempted to use this style from a reference link, so I implemented the following code snippet: $(function () { $('[ID*=search_data]').on('click', function () { var fromda ...

The canDeactivate function in the Angular 2 router can modify the router state even if I choose to cancel an action in the confirmation popup

In my Angular 2 project, I have implemented the canDeactivate method to prevent browser navigation. When a user tries to leave the page, a confirmation popup is displayed. However, if the user chooses to cancel, the router still changes its state even th ...

Eliminate repeated elements in a selection using an AngularJS custom directive

I am in the process of creating an events app that utilizes JSON data from Drupal to showcase events using AngularJS within a Drupal module. One of the keys in the JSON object is 'genre', which I'm utilizing in a select dropdown to allow use ...

Keep Modal Open During Ajax Requests

After clicking the edit button and making changes to the form, I want to reset the page background. However, when I click edit, the form is edited and the modal closes but does not completely close. The div ajaxshow is a layout element that displays the a ...

Designing a framework capable of interpreting Python code and translating it into HTML format

Greetings everyone! I come to you seeking assistance after searching through Google and coming up empty-handed. As a dedicated school teacher, I am in the process of developing an ELearning platform for my students. Right now, my main focus is on creating ...

The functionality of the Ionic menu button becomes disabled once the user has successfully logged in

Having trouble clicking the button after taking a test. Situation: Once logged in -> user takes a test and submits -> redirected to home page. However, unable to click on "Menu button" on the home page. In my Login.ts file: if (this.checker == " ...

Converting Greek text to UTF-8 using Javascript

Currently, I am working on a project with my teacher to digitalize a Greek textbook by transforming it into an online application. This process involves the conversion of a Shapefile, which draws polygons on maps along with polygon descriptions, and mappin ...

Unable to differentiate between .jsx and .js files

Here is the content of my JavaScript file: var React = require('react'); export default class AmortizationChart extends React.Component { render() { var items = this.props.data.map(function (year, index) { ret ...

The compare function in bcryptjs will result in a false output if the passwords include numerical

I have successfully used bcryptjs to hash my passwords during user registration. However, I am facing an issue with the bcrypt.compare function when attempting to log in. The function returns a false promise when passwords contain numbers or special charac ...