Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from sebawo/sw/add_params
Browse files Browse the repository at this point in the history
Add all job paramters values to influx db
  • Loading branch information
karolgil authored Apr 2, 2019
2 parents caa8177 + c17412b commit 0a32339
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.getbase.jenkins.plugins</groupId>
<artifactId>build-history-metrics</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<name>Build history metrics plugin</name>
<description>Jenkins plugin to publish build metrics to external storage</description>
<packaging>hpi</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.getbase.jenkins.plugins.metrics.history.influxdb.generators;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobAction;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Result;
import hudson.model.Run;
import jenkins.metrics.impl.TimeInQueueAction;
Expand Down Expand Up @@ -28,6 +34,25 @@ public JenkinsBasePointGenerator(Run<?, ?> build) {
this.build = build;
}

public Map<String, Object> getBuildParameters(Run build) {
List<ParametersAction> actions = build.getActions(ParametersAction.class);
if (actions != null) {
Map<String, Object> parametersMap = new HashMap<>();
for (ParametersAction action : actions) {
List<ParameterValue> parameters = action.getParameters();
if (parameters != null) {
for (ParameterValue parameter : parameters) {
String name = parameter.getName();
Object value = parameter.getValue();
parametersMap.put(name, value);
}
}
}
return parametersMap;
}
return null;
}

public Point[] generate() {
// Build is not finished when running with pipelines. Duration must be calculated manually
long startTime = build.getTimeInMillis();
Expand All @@ -43,6 +68,8 @@ public Point[] generate() {
final Integer resultInt = resultStr.equals("SUCCESS") ? 1 : 0;
final String jobAbsoluteURL = build.getParent().getAbsoluteUrl();
final String buildAbsoluteURL = jobAbsoluteURL + build.getNumber();
final Run.Summary buildSummary = build.getBuildStatusSummary();
final Map<String, Object> buildParameters = getBuildParameters(build);

Point.Builder point = Point
.measurement(MEASUREMENT_NAME)
Expand All @@ -61,10 +88,11 @@ public Point[] generate() {
.addField(BUILD_DURATION, duration)
.addField(QUEUING_DURATION, action.getQueuingDurationMillis())
.addField(TOTAL_DURATION, duration + action.getQueuingDurationMillis())
.addField(BUILD_STATUS_MESSAGE, build.getBuildStatusSummary().message);
.fields(buildParameters);

return new Point[]{point.build()};
if (buildSummary != null) {
point.addField(BUILD_STATUS_MESSAGE, buildSummary.message);
}
return new Point[] {point.build()};
}


}

0 comments on commit 0a32339

Please sign in to comment.