Skip to content

Commit

Permalink
#48652 - PC Jenkins plugin doesn't accept parameterized values
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldanan committed Jan 11, 2018
1 parent aed2dd0 commit 2a25f05
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 16 deletions.
Expand Up @@ -48,13 +48,13 @@ public class PcModel {
public static final String DO_NOTHING = "Do Not Collate";

private final String serverAndPort;
private final String pcServerName;
private final String almUserName;
private final SecretContainer almPassword;
private final String almDomain;
private final String almProject;
private final String testId;
private final String testInstanceId;
private String pcServerName;
private String almUserName;
private SecretContainer almPassword;
private String almDomain;
private String almProject;
private String testId;
private String testInstanceId;
private final String autoTestInstanceID;
private final TimeslotDuration timeslotDuration;
private final PostRunAction postRunAction;
Expand All @@ -71,7 +71,7 @@ public class PcModel {
@DataBoundConstructor
public PcModel(String serverAndPort, String pcServerName, String almUserName, String almPassword, String almDomain, String almProject,
String testId,String autoTestInstanceID, String testInstanceId, String timeslotDurationHours, String timeslotDurationMinutes,
PostRunAction postRunAction, boolean vudsMode, String description, String addRunToTrendReport, String trendReportId, boolean HTTPSProtocol, String proxyOutURL, String proxyOutUser, String proxyOutPassword) {
PostRunAction postRunAction, boolean vudsMode, String description, String addRunToTrendReport, String trendReportId, boolean HTTPSProtocol, String proxyOutURL, String proxyOutUser, String proxyOutPassword/*, String buildParameters*/) {

this.serverAndPort = serverAndPort;
this.pcServerName = pcServerName;
Expand Down Expand Up @@ -221,4 +221,47 @@ public String isHTTPSProtocol(){
return "http";
return "https";
}

public void setBuildParameters(String buildParameters){
//this.buildParameters=buildParameters;
this.pcServerName=useParameterIfNeeded(buildParameters,this.pcServerName);
this.almUserName=useParameterIfNeeded(buildParameters,this.almUserName);
this.almDomain = useParameterIfNeeded(buildParameters,this.almDomain);
this.almProject = useParameterIfNeeded(buildParameters,this.almProject);
this.testId = useParameterIfNeeded(buildParameters,this.testId);
this.testInstanceId = useParameterIfNeeded(buildParameters,this.testInstanceId);
this.trendReportId = useParameterIfNeeded(buildParameters,this.trendReportId);
String guid="905fe758-94bd-4cbe-b377-affecd6bbdb3";
String parametrizedPassword = useParameterForPasswordIfNeeded(buildParameters,guid);
this.almPassword = parametrizedPassword.equals(guid)? this.almPassword:setPassword(parametrizedPassword);
}

private static String useParameterIfNeeded (String buildParameters,String attribute){
if (buildParameters!=null && attribute!=null) {
if(attribute.startsWith("$")) {
String attributeParameter = attribute.replace("$", "").replace("{", "").replace("}", "");
String[] buildParametersArray = buildParameters.replace("{", "").replace("}", "").split(",");
for (String buildParameter : buildParametersArray) {
if (buildParameter.trim().startsWith(attributeParameter + "=")) {
return buildParameter.trim().replace(attributeParameter + "=", "");
}
}
}
}
return attribute;
}

private static String useParameterForPasswordIfNeeded (String buildParameters, String almPassword){
if (buildParameters!=null) {
String expectedAlmPasswordParameterName = "PCPASSWORD";
String almPasswordFromParameter="";
String[] buildParametersArray = buildParameters.replace("{", "").replace("}", "").split(",");
for (String buildParameter : buildParametersArray) {
if (buildParameter.trim().startsWith(expectedAlmPasswordParameterName + "=")) {
return buildParameter.trim().replace(expectedAlmPasswordParameterName + "=", "");
}
}
}
return almPassword;
}
}
Expand Up @@ -179,6 +179,7 @@ public DescriptorImpl getDescriptor() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
WorkspacePath = new File(build.getWorkspace().toURI());
pcModel.setBuildParameters(((AbstractBuild)build).getBuildVariables().toString());
perform(build, build.getWorkspace(), launcher, listener);

return true;
Expand Down Expand Up @@ -226,6 +227,7 @@ public static String getPcreportFileName() {
private Testsuites execute(PcClient pcClient, Run<?, ?> build)
throws InterruptedException,NullPointerException {
try {
pcModel.setBuildParameters(((AbstractBuild)build).getBuildVariables().toString());
if (!StringUtils.isBlank(pcModel.getDescription()))
logger.println("- - -\nTest description: " + pcModel.getDescription());
if (!beforeRun(pcClient))
Expand All @@ -251,7 +253,7 @@ private Testsuites execute(PcClient pcClient, Run<?, ?> build)
private Testsuites run(PcClient pcClient, Run<?, ?> build)
throws InterruptedException, ClientProtocolException,
IOException, PcException {

pcModel.setBuildParameters(((AbstractBuild)build).getBuildVariables().toString());
PcRunResponse response = null;
String errorMessage = "";
String eventLogString = "";
Expand Down Expand Up @@ -891,12 +893,20 @@ private FormValidation validateHigherThanInt(
ret = FormValidation.error(messagePrefix + "set");
} else {
try {
if (limitIncluded && Integer.parseInt(value) <= limit)
ret = FormValidation.error(messagePrefix + "higher than " + limit);
else if (Integer.parseInt(value) < limit)
ret = FormValidation.error(messagePrefix + "at least " + limit);
//regular expression: parameter (with brackets or not)
if (value.matches("^\\$\\{[\\w-. ]*}$|^\\$[\\w-.]*$"))
return ret;
//regular expression: number
else if (value.matches("[0-9]*$|")) {
if (limitIncluded && Integer.parseInt(value) <= limit)
ret = FormValidation.error(messagePrefix + "higher than " + limit);
else if (Integer.parseInt(value) < limit)
ret = FormValidation.error(messagePrefix + "at least " + limit);
}
else
ret = FormValidation.error(messagePrefix + "a whole number or a parameter, e.g.: 23, $TESTID or ${TEST_ID}.");
} catch (Exception e) {
ret = FormValidation.error(messagePrefix + "a whole number");
ret = FormValidation.error(messagePrefix + "a whole number or a parameter (e.g.: $TESTID or ${TestID})");
}
}

Expand Down
Expand Up @@ -166,7 +166,10 @@
<td colspan="2">
<div class="help" style="display:block;">
${%DontForgetThePublisher}
</div>
</div>
<div class="help" style="display:block;">
${%ParametrizationMessage}
</div>
</td>
<td />
</tr>
Expand Down
Expand Up @@ -33,4 +33,7 @@

DontForgetThePublisher=Don''t forget to enable the <strong>Publish HPE \
tests result</strong> option in the <strong>Post-build \
Actions</strong> section so that the tests results are published.
Actions</strong> section so that the tests results are published.
ParametrizationMessage= The following fields can be parametrized: <strong>''PC Server''</strong>, <strong>''User name''</strong>, <strong>''Domain''</strong>, \
<strong>''Project''</strong>, <strong>''Test ID''</strong>, <strong>''Test Instance ID''</strong> and <strong>''Trend report ID''</strong>. <br>To parametrize the Password of the PC User, \
create a ''Password Parameter'' in this configuration job and name it <strong>''PCPASSWORD''</strong>.

0 comments on commit 2a25f05

Please sign in to comment.