如何在import
中使用Jenkinsfile
语句?
这是导入语句:
import hudson.model.*
import jenkins.model.*
import hudson.tasks.test.AbstractTestResultAction
我想在AbstractTestResultAction
部分中使用script
。
答案 0 :(得分:0)
我以这种方式解决了它-Jenkinsfile
的样子:
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import hudson.tasks.test.AbstractTestResultAction;
@NonCPS
def getTestSummary = { ->
def testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
def summary = ""
if (testResultAction != null) {
def total = testResultAction.getTotalCount()
def failed = testResultAction.getFailCount()
def skipped = testResultAction.getSkipCount()
summary = "Test results:\n\t"
summary = summary + ("Passed: " + (total - failed - skipped))
summary = summary + (", Failed: " + failed + " ${testResultAction.failureDiffString}")
summary = summary + (", Skipped: " + skipped)
} else {
summary = "No tests found"
}
return summary
}
pipeline {
...
post {
always {
script {
def testSummaryRaw = getTestSummary()
def testSummary = "`${testSummaryRaw}`"
...
}
}
}
...
}