I have the following problem: I execute a windows batch file on a Jenkins server and have to split a multi-line environment variable (set vía a Jenkins parameter) into single li
Well as reflex I propose you the following solution:
If python is installed (if not ... up to you to install it .. it is usefull ;-) )
in your batch line : Python MyScriptToExecuteEachLinesFromVar.py varname "myprog.exe -baz 0 -meow"
With the script content:
import sys,os # libraries used : system and operating system
if len(sys.argv)>0: # if arguments provided (at least the variable name)
varname = sys.argv[1] # the variable name is the second argument (0=script)
prefix = " ".join(sys.argv[2:]) # the list of all others are the prefix.
lines = os.environ[varname].split('\n') # get the var and split lines
for f in lines :
print "execute:", prefix, f
os.system(prefix+" "+f) # execute each line with the given prefix.
Hope it helps.