Home > Blockchain >  Getting url data from web and using it in jenkins job
Getting url data from web and using it in jenkins job

Time:11-04

I have a jenkins job and part of it is going to a file in azure blob and getting the info 'https://bla.blob.core.windows.net/data/ips.txt' the content is

1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4

id like jenkins to build a string array from it and pass it to another command. problem is when i use:

def response = httpRequest 'https://blabla.blob.core.windows.net/data/ips.txt'

and then try pass the response to the other command there's a problem since the data coming as one big String:

1.1.1.1\n2.2.2.2\3.3.3.3...

how can i convert this to String array?

CodePudding user response:

Split Method

There is a split method on Strings in groovy. You can split your String into a list as follows

def str = "1.1.1.1\n2.2.2.2\n3.3.3.3"
def strArr = str.split("\n") // this is what you want to send

// Printing the array so you can see it appropriately split
strArr.each{
    println it
}
  • Related