如何从文件中读取行并将其存储在groovy中的数组中?

时间:2019-06-07 06:22:09

标签: string jenkins-pipeline jenkins-groovy

我试图从文件中读取IPADDRESSES / HOSTNAMES,并将每个IP地址存储到Jenkinsfile中数组的不同元素中。 我尝试过的步骤如下。

def absoluteFilePath = "/root/myhosts"
def fileContent = readFile(absoluteFilePath)
String[] listOfServers = fileContent.split('\n')            
for (int i = 0; i < listOfServers.size(); i++) 
{                           
def remote = [:]    
remote.host = "${listOfServers[i]}"    
remote.name = "node-1"    
remote.allowAnyHosts = true    
sh 'ping -c 4 ${listOfServers[i]}'    
}

*Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to Anurag_CentOS
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1741)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
at hudson.remoting.Channel.call(Channel.java:955)
at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:71)
at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution$1.call(SSHStepExecution.java:73)
at hudson.security.ACL.impersonate(ACL.java:290)
at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution.lambda$start$0(SSHStepExecution.java:68)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:519)
at com.jcraft.jsch.Session.connect(Session.java:183)
at com.jcraft.jsch.Session$connect$1.call(Unknown Source)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE*

0 个答案:

没有答案
相关问题