-
Notifications
You must be signed in to change notification settings - Fork 100
basic Jenkins pipeline support for notifier #185
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ target/ | |
.gradle | ||
local.properties | ||
**build | ||
/bin/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,8 @@ | |
import com.uber.jenkins.phabricator.utils.CommonUtils; | ||
import com.uber.jenkins.phabricator.utils.Logger; | ||
import hudson.FilePath; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.Result; | ||
import hudson.model.Run; | ||
import net.sf.json.JSONException; | ||
import net.sf.json.JSONObject; | ||
|
||
|
@@ -59,15 +59,15 @@ public class BuildResultProcessor { | |
private final String buildUrl; | ||
private final boolean runHarbormaster; | ||
private final FilePath workspace; | ||
private final AbstractBuild build; | ||
private final Run<?, ?> build; | ||
private String commentAction; | ||
private final CommentBuilder commenter; | ||
private UnitResults unitResults; | ||
private Map<String, String> harbormasterCoverage; | ||
private LintResults lintResults; | ||
|
||
public BuildResultProcessor( | ||
Logger logger, AbstractBuild build, Differential diff, DifferentialClient diffClient, | ||
Logger logger, Run<?, ?> build, FilePath workspace, Differential diff, DifferentialClient diffClient, | ||
String phid, CodeCoverageMetrics coverageResult, String buildUrl, boolean preserveFormatting, | ||
CoverageCheckSettings coverageCheckSettings) { | ||
this.logger = logger; | ||
|
@@ -76,7 +76,7 @@ public BuildResultProcessor( | |
this.phid = phid; | ||
this.buildUrl = buildUrl; | ||
this.build = build; | ||
this.workspace = build.getWorkspace(); | ||
this.workspace = workspace; | ||
|
||
this.commentAction = "none"; | ||
this.commenter = new CommentBuilder(logger, build.getResult(), coverageResult, buildUrl, preserveFormatting, | ||
|
@@ -85,7 +85,11 @@ public BuildResultProcessor( | |
} | ||
|
||
public Result getBuildResult() { | ||
return this.build.getResult(); | ||
if (this.build.getResult() == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why we would want to return success on null? It seems a bit counterintuitive. Are there any api docs defining this new behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on oldschool freestyle jobs after the build reached the last build step it set the build result to success, but in pipeline there is no definite end of build blocks, so it won't explicitly set SUCCESS, hence the previous workaround, where it was needed to run this before the notifier: currentBuild.result = currentBuild.result ?: 'SUCCESS' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The phab notifier build step need not necessarily be the last step. If someone uses pipeline and not this plugin, they would have to workaround this anyways, so this logic should not be in this plugin. This should be reported upstream to jenkins. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null == success so far. IMHO it was a genuine missing null check in the plugin code. In freestyle it is always set and in pipeline it is always considered SUCCESS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense |
||
return Result.SUCCESS; | ||
} else { | ||
return this.build.getResult(); | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
|
||
import hudson.FilePath; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.Run; | ||
import hudson.plugins.cobertura.Ratio; | ||
import hudson.plugins.cobertura.targets.CoverageMetric; | ||
import hudson.plugins.cobertura.targets.CoverageResult; | ||
|
@@ -96,7 +97,8 @@ Map<String, List<Integer>> parseReports(CoberturaXMLParser parser, File[] report | |
} | ||
|
||
private void computeCoverage() { | ||
AbstractBuild build = getBuild(); | ||
Run<?, ?> build = getBuild(); | ||
FilePath workspace = getWorkspace(); | ||
if (build == null) { | ||
mHasComputedCoverage = true; | ||
return; | ||
|
@@ -114,7 +116,7 @@ private void computeCoverage() { | |
} | ||
|
||
// Fallback to scanning for the reports | ||
copyCoverageToJenkinsMaster(build); | ||
copyCoverageToJenkinsMaster(build, workspace); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just inline There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the new Jenkins API you can't use Build, but must use Run, but the run interface won't provide a getWorkspace method. I can change this call to this: copyCoverageToJenkinsMaster(build, getWorkspace()); but this is the best I can do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets leave it as is then |
||
File[] reports = getCoberturaReports(build); | ||
CoverageResult result = null; | ||
if (reports != null) { | ||
|
@@ -142,17 +144,14 @@ private void computeCoverage() { | |
} | ||
|
||
private void computeLineCoverage() { | ||
FilePath workspace = getBuild().getWorkspace(); | ||
FilePath workspace = getWorkspace(); | ||
File[] reports = getCoberturaReports(getBuild()); | ||
CoberturaXMLParser parser = new CoberturaXMLParser(workspace, getIncludeFileNames()); | ||
mLineCoverage = parseReports(parser, reports); | ||
} | ||
|
||
private void copyCoverageToJenkinsMaster(AbstractBuild build) { | ||
final FilePath[] moduleRoots = build.getModuleRoots(); | ||
final boolean multipleModuleRoots = | ||
moduleRoots != null && moduleRoots.length > 1; | ||
final FilePath moduleRoot = multipleModuleRoots ? build.getWorkspace() : build.getModuleRoot(); | ||
private void copyCoverageToJenkinsMaster(Run<?, ?> build, FilePath workspace) { | ||
final FilePath moduleRoot = workspace; | ||
final File buildCoberturaDir = build.getRootDir(); | ||
FilePath buildTarget = new FilePath(buildCoberturaDir); | ||
|
||
|
@@ -225,7 +224,7 @@ private static float getCoveragePercentage(CoverageResult result, CoverageMetric | |
return ratio.getPercentageFloat(); | ||
} | ||
|
||
private File[] getCoberturaReports(AbstractBuild build) { | ||
private File[] getCoberturaReports(Run<?, ?> build) { | ||
return build.getRootDir().listFiles(CoberturaPublisher.COBERTURA_FILENAME_FILTER); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this required? Can we decouple this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered in #185 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good