can I use the method execute() in script Groovy for Jenkins in order to execute shell command?
What is the best way to execute command shell in Groovy script for Jenkins?
class Example {
static void main(String[] args) {
def map = [:]
def array = new File('deployable.txt') as String[];
def versionDate = "snapshot"
for(String i in array) {
String[] splitedPath =i.split("/");
int indexFilename = splitedPath.length -1
String fileName = splitedPath [indexFilename]
println(fileName)
String []name =fileName.split('.t')
String nameOri =name[0]
println(nameOri)
nameOri = nameOri+"-"+versionDate+".txt"
map.put(i, nameOri )
}
map.each{entry ->
println "$entry.key: $entry.value"
def source ="$entry.key"
def dest="$entry.value"
def command = 'touch '+source
println command
command.execute()
command = 'mv '+source +' test/'+dest
command.execute()
}
}
}