1
我想读取工作区中的文件。该文件是在上一步中创建的(通过对java的shell脚本调用)。我已经证实它存在。我正在使用'readFile'。我得到下面的例外。我可以在shell脚本中访问这个文件,但我想做一些json解析,而不是使用groovy。这里有一些安全措施可以阻止访问吗?Jenkins工作流程-filenotfound工作区文件
java.io.FileNotFoundException: /var/lib/jenkins/jobs/MBTest/branches/develop/workspace/functional-tests/target/scalatestcuke-F63QUALZN4.json
(No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at hudson.FilePath.read(FilePath.java:1751)
at org.jenkinsci.plugins.workflow.steps.ReadFileStep$Execution.run(ReadFileStep.java:87)
at org.jenkinsci.plugins.workflow.steps.ReadFileStep$Execution.run(ReadFileStep.java:81)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:49)
at hudson.security.ACL.impersonate(ACL.java:213)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
的Jenkinsfile(略有减少)
#!groovy
// Execute the following steps on the master
node {
stage name: 'Checkout', concurrency: 1
checkout scm
functionalTest()
release()
}
def functionalTest(){
stage name: 'QA', concurrency: 1
echo "nonrestF63"
sh scalatestScript("F63QUALZN4","latest",5922,"-l jhc.TDRest")
archive includes: 'functional-tests/target/*.json'
def job = build job: 'generic-cucumber-report', parameters: [
[$class: 'StringParameterValue', name: 'projectname', value: 'MBTest/develop'],
[$class: 'StringParameterValue', name: 'jsondir', value: 'functional-tests/target']]
step ([$class: 'CopyArtifact',
projectName: 'generic-cucumber-report',
filter: 'target/cucumber-html-reports/**/*',
selector: [$class: 'SpecificBuildSelector', buildNumber: job.getId()]]);
publishHTML(target: [allowMissing: false, keepAll: true, reportDir: 'target/cucumber-html-reports/',
reportFiles: 'feature-overview.html', reportName: 'Test results'])
def failures = countFailures()
if(failures > 0){
error '${failures} test failures reported'
}
}
def countFailures() {
sh "ls functional-tests/target/*.json | sed -e ':a' -e 'N' -e '\$!ba' -e 's/\\n/,/g' > filelist.txt"
def txt = readFile "filelist.txt"
def count = 0
txt.split(",") each { jsonFile ->
def text = readFile jsonFile
def json = new groovy.json.JsonSlurper().parseText(text)
count = count + countMatches(json,"status","failed")
}
return count
}
问题可以在countfailures方法可以看出。我从WS读取一个文件列表,并循环访问这些名称。当我尝试阅读文件时,虽然我获得了FNF。
你能后的ReadFile的一步? –
和它周围的代码,我应该添加。 –
对不起,我不知道如何设置SO线程更新通知,或者没有我需要的通知。 –