我正在尝试在工作区中读取文件。该文件是在上一步中创建的(通过对java脚本的shell脚本调用)。我确认它存在。我正在使用' readFile'。我在下面得到了例外。我可以在shell脚本中访问这个文件,但我想做一些json解析,而且更喜欢使用groovy。这里有一些安全措施阻止访问吗?
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)
Jenkins文件(略微减少)
#!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。
答案 0 :(得分:-1)
你可以使用这种代码安静,你将从当前版本中获得最新的人工制品。
step ([$class: 'CopyArtifact', projectName: 'Pipeline', filter: '**.txt', selector: [$class: 'SpecificBuildSelector', buildNumber: env.BUILD_NUMBER]])