Skip to content

Commit

Permalink
[FIXED JENKINS-12384] Error when saving reports while multiple tests …
Browse files Browse the repository at this point in the history
…are run
  • Loading branch information
rseguy committed Jan 12, 2012
1 parent 11bed99 commit bf063f7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright (c) 2010-2011, Manufacture Française des Pneumatiques Michelin,
* Copyright (c) 2010-2012, Manufacture Française des Pneumatiques Michelin,
* Thomas Maurel, Romain Seguy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -39,6 +39,7 @@
import hudson.model.BuildListener;
import hudson.model.Computer;
import hudson.model.Hudson;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.tools.ToolInstallation;
Expand All @@ -52,7 +53,9 @@
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -102,6 +105,14 @@ public class QualityCenter extends Builder {
private String parsedQcTSLogFile;
private String runMode;
private String runHost;

// parsedQcTSLogFiles is used by QualityCenterResultArchiver in order to gather
// the name of the report files which have been generated by the build step. This
// is mandatory to have this because the name of the generated report files may
// not be the one specified by the user (which happens if several test sets have
// to be run in one build step and if the name specified by the user can't be
// unique).
private transient List<String> testSetLogFiles;

@DataBoundConstructor
public QualityCenter(
Expand Down Expand Up @@ -187,7 +198,7 @@ public String getQcTSLogFile() {
public String getParsedQcTSLogFile() {
return parsedQcTSLogFile;
}

public String getQcTSName() {
return qcTSName;
}
Expand All @@ -204,6 +215,13 @@ public String getRunHost() {
return runHost;
}

/**
* @see QualityCenterResultArchiver#perform(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.BuildListener)
*/
List<String> getTestSetLogFiles() {
return testSetLogFiles;
}

public static String getVbScriptName() {
return VB_SCRIPT_NAME;
}
Expand Down Expand Up @@ -284,9 +302,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
vbScript.copyFrom(vbsUrl);

try {
testSetLogFiles = new ArrayList<String>();

// For each TestSet, run the VBScript
for(String testSetName : Util.replaceMacro(env.expand(this.qcTSName), build.getBuildVariableResolver()).split("[\t\r\n,]+")) {
String logFile = runVBScript(testSetName, build, launcher, listener, vbScript);
String[] testSetNames = Util.replaceMacro(env.expand(this.qcTSName), build.getBuildVariableResolver()).split("[\t\r\n,]+");
for(String testSetName : testSetNames) {
String logFile = runVBScript(testSetName, build, launcher, listener, vbScript, (testSetNames.length == 1));
// Has the report been successfuly generated?
if(!projectWS.child(logFile).exists()) {
listener.fatalError(Messages.QualityCenter_ReportNotGenerated());
Expand Down Expand Up @@ -332,7 +353,7 @@ private void removeEnvVars(EnvVars env) {
/**
* Runs the given TestSet ({@code testSetName}) through VBScript.
*/
private String runVBScript(String testSetName, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, FilePath file) throws IOException, InterruptedException {
private String runVBScript(String testSetName, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, FilePath file, boolean isRunOnce) throws IOException, InterruptedException {
ArgumentListBuilder args = new ArgumentListBuilder();
EnvVars env = build.getEnvironment(listener);
VariableResolver<String> varResolver = build.getBuildVariableResolver();
Expand All @@ -343,6 +364,17 @@ private String runVBScript(String testSetName, AbstractBuild<?, ?> build, Launch

// Parse the report file name using env vars
this.parsedQcTSLogFile = Util.replaceMacro(env.expand(this.qcTSLogFile), varResolver);
if(!parsedQcTSLogFile.endsWith(".xml")) {
parsedQcTSLogFile = parsedQcTSLogFile + ".xml";
}
if(!isRunOnce && !parsedQcTSLogFile.contains(testSetName)) {
// JENKINS-12384: One file must be generated per test set. As such we must
// ensure that the name of each file is unigue. We consider it is the case
// if the name of the file contains the name of the test set. Otherwise,
// we add it.
parsedQcTSLogFile = parsedQcTSLogFile.substring(0, parsedQcTSLogFile.length()-4) + '_' + testSetName + ".xml";
}
testSetLogFiles.add(parsedQcTSLogFile);

// Use cscript to run the vbscript and get the console output

Expand Down
Expand Up @@ -78,7 +78,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
// Get the TestSet report files names of the current build
for(Builder builder : builders) {
if(builder instanceof QualityCenter) {
names.add(((QualityCenter)builder).getParsedQcTSLogFile());
names.addAll(((QualityCenter) builder).getTestSetLogFiles());
}
}

Expand Down
@@ -1,7 +1,8 @@
<!--
- The MIT License
-
- Copyright (c) 2010, Manufacture Française des Pneumatiques Michelin, Thomas Maurel
- Copyright (c) 2010-212, Manufacture Française des Pneumatiques Michelin,
- Thomas Maurel, Romain Seguy
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,11 +24,18 @@
-->

<div>
You can use all standard environment variables plus:
<p>Name of the report that will be generated.</p>
<p>If several test sets are run in one build step, one report will be generated
per test set. As such, you must ensure that the name will be unique by including
the test set name in it (through the <code>${TS_NAME}</code> variable). If it's
not the case, then the name will be automatically post fixed with an underscore
followed by the test set name.</p>
<p>You can use all standard environment variables plus:
<ul>
<li><code>${QC_DOMAIN}</code> for the current Quality Center domain;</li>
<li><code>${QC_PROJECT}</code> for the current Quality Center project;</li>
<li><code>${TS_FOLDER}</code> for the current TestSet folder;</li>
<li><code>${TS_NAME}</code> for the TestSet name.</li>
</ul>
</p>
</div>
@@ -1,7 +1,8 @@
<!--
- The MIT License
-
- Copyright (c) 2010, Manufacture Française des Pneumatiques Michelin, Thomas Maurel
- Copyright (c) 2010-212, Manufacture Française des Pneumatiques Michelin,
- Thomas Maurel, Romain Seguy
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,11 +24,19 @@
-->

<div>
Vous pouvez utiliser toutes les variables d'environnement usuelles plus :
<p>Nom du rapport à générer.</p>
<p>Si plusieurs TestSets doivent être exécutés, alors un rapport sera généré
par TestSet. En conséquence, vous devez vous assurer que le nom de chaque
rapport sera unique en y incluant le nom du TestSet correspondant (grâce à la
variable <code>${TS_NAME}</code> variable). Si ça n'est pas le cas, alors le
nom sera automatiquement modifié : il sera suffixé par un souligné suivi du
nom du TestSet.</p>
<p>Vous pouvez utiliser toutes les variables d'environnement usuelles plus :
<ul>
<li><code>${QC_DOMAIN}</code> pour le domaine Quality Center ;</li>
<li><code>${QC_PROJECT}</code> pour le projet Quality Center ;</li>
<li><code>${TS_FOLDER}</code> pour le répertoire du TestSet ;</li>
<li><code>${TS_NAME}</code> pour le nom du TestSet.</li>
</ul>
</p>
</div>
4 changes: 2 additions & 2 deletions src/main/resources/runTestSet.vbs
@@ -1,6 +1,6 @@
' The MIT License
'
' Copyright (c) 2010-2011, Manufacture Française des Pneumatiques Michelin,
' Copyright (c) 2010-2012, Manufacture Française des Pneumatiques Michelin,
' Thomas Maurel, CollabNet, Johannes Nicolai, Shane Smart, Mickael Beluet,
' Romain Seguy
'
Expand Down Expand Up @@ -514,7 +514,7 @@ Class QCTestRunner
lStatus = ""

If test.Failure Is Nothing Then
body = body & vbTab & "</testcase>" & vbCrLf
body = body & vbTab & "</testcase>" & vbCrLf
lStatus = "Passed"

Elseif test.Status = "No Run" or test.Status = "Condition Failed" Then ' the test didn't run
Expand Down

0 comments on commit bf063f7

Please sign in to comment.