jenkins - For loop in groovy with two list of variables -
i have list of batch commands performs xcopy 's, this. jenkins pipeline script:
bat "xcopy %cd%${some_path1}\\obj\\lab5\\package\\packagetmp ${host1}\\dir1 /e /y /v" bat "xcopy %cd%${some_path2}\\obj\\lab5\\package\\packagetmp ${host1}\\dir2 /e /y /v" bat "xcopy %cd%${some_path3}\\obj\\lab5\\package\\packagetmp ${host1}\\dir3 /e /y /v"
how use loop in groovy, can have 1 line of batch command , pass value of variables ("some_path1", "some_path2", "some_path3")
& ("dir1", "dir2", "dir3")
so, given list of paths:
def paths = ['some_path1', 'some_path2', 'another_path']
and list of directories each path (in 1:1 relationship)
def dirs = ['dir1', 'dir_for_some_path2', 'another_dir']
you can do:
[paths, dirs].transpose().each { path, dir -> bat "xcopy %cd%${path}\\obj\\lab5\\package\\packagetmp host1\\${dir} /e /y /v" }
in case have ancient version of groovy, try
[paths, dirs].transpose().each { pd -> def path = pd[0] def dir = pd[1] bat "xcopy %cd%${path}\\obj\\lab5\\package\\packagetmp host1\\${dir} /e /y /v" }
Comments
Post a Comment