1. 程式人生 > 其它 >Jenkins的pipeline寫groovy指令碼-如何判斷檔案是否存在

Jenkins的pipeline寫groovy指令碼-如何判斷檔案是否存在

技術標籤:JenkinsJenkinsgroovypipeline檔案是否存在

判斷在工作目錄下是否存在**/target/failsafe-reports/TEST-*.xml的檔案,如果存在就執行操作。

stage('Scan'') {
    dir("${WORKSPACE}"){
        script {
            try{
				out = sh(script: "[ -f **/target/failsafe-reports/TEST-*.xml ]  && echo 'true' || echo 'false' ", returnStdout: true)
				println out
				if(out == "true") {
                junit '**/target/failsafe-reports/TEST-*.xml'
				echo "failsafe-reports exist."
				}
            } catch(Exception e) {
				println e
				echo("failsafe-reports does not exist.")
			}
		}
    }
}

附加:

Jenkins如何掃描到IT測試類,並在UI上顯示統計結果?

用Junit外掛就可以,Junit既可以掃描到Unit Test ,也可以掃描到IT Test。

在需要的指令碼上加上以下命令就行,掃描的路徑根據自己個人專案修改。

junit '**/target/failsafe-reports/TEST-*.xml'