简体   繁体   中英

Getting url data from web and using it in jenkins job

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?

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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