-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
by using a separate step.
- Loading branch information
Showing
6 changed files
with
112 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/hudson/plugins/gradle/BuildScanLogScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package hudson.plugins.gradle; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class BuildScanLogScanner { | ||
private final BuildScanPublishedListener listener; | ||
private int linesSinceBuildScanPublishingMessage = Integer.MAX_VALUE; | ||
private static final Pattern BUILD_SCAN_PATTERN = Pattern.compile("Publishing (build scan|build information)\\.\\.\\."); | ||
private static final Pattern URL_PATTERN = Pattern.compile("https?://\\S*"); | ||
|
||
public static final int MAX_PUBLISHED_MESSAGE_LENGTH = 70; | ||
|
||
public BuildScanLogScanner(BuildScanPublishedListener listener) { | ||
this.listener = listener; | ||
} | ||
|
||
void scanLine(String line) { | ||
if (linesSinceBuildScanPublishingMessage < 10) { | ||
linesSinceBuildScanPublishingMessage++; | ||
Matcher matcher = URL_PATTERN.matcher(line); | ||
if (matcher.find()) { | ||
linesSinceBuildScanPublishingMessage = Integer.MAX_VALUE; | ||
String buildScanUrl = matcher.group(); | ||
listener.onBuildScanPublished(buildScanUrl); | ||
} | ||
} | ||
if (line.length() < MAX_PUBLISHED_MESSAGE_LENGTH && BUILD_SCAN_PATTERN.matcher(line).find()) { | ||
linesSinceBuildScanPublishingMessage = 0; | ||
} | ||
|
||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/hudson/plugins/gradle/BuildScanPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package hudson.plugins.gradle; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import hudson.Extension; | ||
import hudson.model.Run; | ||
import org.jenkinsci.plugins.workflow.steps.Step; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor; | ||
import org.jenkinsci.plugins.workflow.steps.StepExecution; | ||
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.BufferedReader; | ||
import java.util.Set; | ||
|
||
public class BuildScanPublisher extends Step { | ||
@DataBoundConstructor | ||
public BuildScanPublisher() { | ||
} | ||
|
||
@Override | ||
public StepExecution start(StepContext context) { | ||
return new Execution(context); | ||
} | ||
|
||
static class Execution extends SynchronousNonBlockingStepExecution<Void> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
protected Execution(@Nonnull StepContext context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
protected Void run() throws Exception { | ||
Run run = getContext().get(Run.class); | ||
BufferedReader logReader = new BufferedReader(run.getLogReader()); | ||
BuildScanLogScanner scanner = new BuildScanLogScanner(new DefaultBuildScanPublishedListener(run)); | ||
logReader.lines().forEach(scanner::scanLine); | ||
return null; | ||
} | ||
} | ||
|
||
@Extension | ||
public static final class DescriptorImpl extends StepDescriptor { | ||
|
||
@Override | ||
public Set<? extends Class<?>> getRequiredContext() { | ||
return ImmutableSet.of(Run.class); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return "Find published build scans"; | ||
} | ||
|
||
@Override | ||
public String getFunctionName() { | ||
return "findBuildScans"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/resources/hudson/plugins/gradle/BuildScanPublisher/help.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div> | ||
Inspect build log for published Gradle build scans. | ||
The build scans will be shown on the pipeline build page. | ||
</div> |