2016-03-04 99 views
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。

+0

你能後的ReadFile的一步? –

+0

和它周圍的代碼,我應該添加。 –

+0

對不起,我不知道如何設置SO線程更新通知,或者沒有我需要的通知。 –

回答

-1

你可以使用這個代碼和平,你會得到從當前版本最新的假象。

step ([$class: 'CopyArtifact', projectName: 'Pipeline', filter: '**.txt', selector: [$class: 'SpecificBuildSelector', buildNumber: env.BUILD_NUMBER]])