Java 即使测试失败,如何始终在Jenkins Groovy管道中写入.csv数据文件
我有一个使用TestNG生成新客户数据的测试:Java 即使测试失败,如何始终在Jenkins Groovy管道中写入.csv数据文件,java,jenkins,jenkins-pipeline,filewriter,Java,Jenkins,Jenkins Pipeline,Filewriter,我有一个使用TestNG生成新客户数据的测试: public class GenerateNewCustomers{ private static ArrayList<String> customers = new ArrayList<>(); @Test(invocationCount = 5) public void runApplicationGeneration() throws InterruptedException { api = new Ag
public class GenerateNewCustomers{
private static ArrayList<String> customers = new ArrayList<>();
@Test(invocationCount = 5)
public void runApplicationGeneration() throws InterruptedException {
api = new AgreementApiCalls();
api.createNewCustomer();//more api calls to enrich customer object
api.customers = api.insertNewcustomer();
setCustomers(customers);
@AfterClass
public void writeTestData() throws IOException {
generateTestDataFile();
}
private static void setCustomers(ArrayList<String> customers) {
GenerateNewCustomers.customers = customers;
}
private void generateTestDataFile() throws IOException {
FileWriter writer = new FileWriter("src/test/resources/testData.csv");
List<String> test = new ArrayList<>(customers);
String collect = test.stream().collect(Collectors.joining(","));
writer.write(collect);
writer.close();
}
如果出现异常,我认为您缺少了
archiveArtifacts
。尝试将其移动到适当的post
子句,如下所示:
pipeline {
stages {...}
post {
always {
archiveArtifacts artifacts: "src/test/resources/testData.csv", fingerprint: true
}
}
}
尝试/抓住总是流行的案例
try {
stage('test') {
// test
}
}
catch(e) {
// print stack trace, message ...
currentBuild.result = 'FAILURE'
}
finally {
// always run there
}
还请分享围绕引用代码部分的其余管道脚本(可能删除了不相关的步骤)。@AlexO谢谢-为了清晰起见,我添加了完整的管道脚本
try {
stage('test') {
// test
}
}
catch(e) {
// print stack trace, message ...
currentBuild.result = 'FAILURE'
}
finally {
// always run there
}