Jenkins groovy插件文件未找到异常
我有一个脚本,可以找到所有空闲的从机,并使用Jenkins系统groovy创建一个文本文件。我能够创建一个空文件,并找到所有空闲的从机,然后将其附加到我得到的文件“idle_slaves.list”中java.io.FileNotFoundExceptionexception。有人能帮我吗Jenkins groovy插件文件未找到异常,jenkins,groovy,jenkins-plugins,jenkins-groovy,Jenkins,Groovy,Jenkins Plugins,Jenkins Groovy,我有一个脚本,可以找到所有空闲的从机,并使用Jenkins系统groovy创建一个文本文件。我能够创建一个空文件,并找到所有空闲的从机,然后将其附加到我得到的文件“idle_slaves.list”中java.io.FileNotFoundExceptionexception。有人能帮我吗 import jenkins.* import hudson.* import jenkins.model.Jenkins jenkins = jenkins.model.Jenkins File fil
import jenkins.*
import hudson.*
import jenkins.model.Jenkins
jenkins = jenkins.model.Jenkins
File file1 = new File(build.workspace.toString() + "/idle_slaves.list")
if(build.workspace.isRemote())
{
channel = build.workspace.channel;
fp = new FilePath(channel, build.workspace.toString() + "/idle_slaves.list")
} else {
fp = new FilePath(new File(build.workspace.toString() + "/idle_slaves.list"))
}
if(fp != null)
{
fp.write("", null); //writing to file
}
for (node in Jenkins.instance.nodes) {
computer = node.toComputer()
if (computer.getChannel() == null) {
continue
}
if (computer.isIdle()) {
slave = node.name.toString()
file1.append( slave )
}
}
詹金斯2.46
groovy 2.0
实际上,文件本身尚未创建:) 如果要创建文件,只需创建一个指向路径的指针,然后添加以下行
file1.createNewFile()
还要确保您创建的文件具有访问权限,否则您将被拒绝
添加以下代码以进行确认
// check if the file exists
boolean exists = file.exists();
if(exists == true)
{
// printing the permissions associated with the file
println "Executable: " + file.canExecute();
println "Readable: " + file.canRead();
println "Writable: "+ file.canWrite();
}
else
{
println "File not found.";
}
希望有帮助:)为什么不使用jenkins/hudson库而不是手动阅读:
pipeline {
agent {label 'slave'}
stages {
...
}
}
def jenkins = Jenkins.instance
def computers = jenkins.computers
computers.each{
println "${it.displayName} ${it.hostName}"
}
for (aSlave in hudson.model.Hudson.instance.slaves) {
pipeline {
agent {label 'slave'}
stages {
...
}
}
def jenkins = Jenkins.instance
def computers = jenkins.computers
computers.each{
println "${it.displayName} ${it.hostName}"
}
for (aSlave in hudson.model.Hudson.instance.slaves) {
pipeline {
agent {label 'slave'}
stages {
...
}
}
def jenkins = Jenkins.instance
def computers = jenkins.computers
computers.each{
println "${it.displayName} ${it.hostName}"
}
for (aSlave in hudson.model.Hudson.instance.slaves) {
pipeline {
agent {label 'slave'}
stages {
...
}
}
def jenkins = Jenkins.instance
def computers = jenkins.computers
computers.each{
println "${it.displayName} ${it.hostName}"
}
for (aSlave in hudson.model.Hudson.instance.slaves) {
这意味着找不到该文件。或者可能无法访问。错误行?你能分享你的堆栈跟踪吗?还有你的要求是什么,也许还有其他的方法。我想找到空闲的奴隶并在每个奴隶上运行一个作业。