Skip to content

Conversation

nfalco79
Copy link
Member

@nfalco79 nfalco79 commented Aug 24, 2025

Define an extension point to customize the build status with optional data or change only some basic data (description, build number and so on).

Example of Bitbucket Data Center to add test result (Cloud has report on code insign reports, maybe separate PR for this).

@Extension
class BuildStatusTestResultCustomizer implements BitbucketBuildStatusCustomizer {

	@Override
	public void customize(@NonNull Run<?, ?> build, @NonNull BitbucketBuildStatus buildStatus) {
		if (buildStatus.getState() != null && buildStatus.getState() != Status.INPROGRESS) {
			// add test result only when build is completed
			List<AbstractTestResultAction> testResultActions = build.getActions(AbstractTestResultAction.class);
			if (testResultActions.isEmpty()) {
				return null;
			}
			TestResults tests = testResultActions.stream()
				.collect(TestResultSummary::new, TestResultSummary::accept, TestResultSummary::combine)
				.getTestResults();

			buildStatus.addOptionalData("testResults", tests);
		}
	}

	@Override
	public boolean isApplicable(EndpointType type) {
		return type == EndpointType.SERVER;
	}

    private static class TestResultSummary {

        private int totalCount;
        private int failCount;
        private int skipCount;

        void accept(@NonNull AbstractTestResultAction<?> value) {
            totalCount += value.getTotalCount();
            failCount += value.getFailCount();
            skipCount += value.getSkipCount();
        }

        void combine(@NonNull TestResultSummary other) {
            totalCount += other.totalCount;
            failCount += other.failCount;
            skipCount += other.skipCount;
        }

        @NonNull
        TestResults getTestResults() {
            return new TestResults( totalCount - failCount - skipCount, failCount, skipCount);
        }
    }
}
immagine

Copy link
Contributor

@KalleOlaviNiemitalo KalleOlaviNiemitalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the diff on a phone, didn't load to any IDE yet.

return optionalData;
}

public void setOptionalData(Map<String, Object> optionalData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'd like some reference to com.fasterxml.jackson so that callers understand what kind of Object can be put in the map and how it will be serialised.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought long about how to make it extensible:

  • In my first attempts, I tried using subclasses, but calling different customizers in a cascade would return different objects.
  • The second was a map that is serialized excluding the container element.

Using a JsonNode it's not possible (from what I know) to achieve the same result. It also means that customizers would have to have jackson among their dependencies. In this way, a customizer can simply add any type of object. It's up to the implementer to provide a properly serializable bean.
Have a look to ServerBuildStatusCustomizer how is simple is add a testResults data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add javadoc, replace setter of the map with method to set a single entry (this should avoid delete info populated by other customizers)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention "bean" in the javadoc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean instead of optionalData?
@param bean value associate to the given key
or
@param optionalData bean associate to the given key
?

@nfalco79 nfalco79 force-pushed the feature/JENKINS-76027 branch from cadd390 to a98b9a3 Compare August 25, 2025 11:46
Define extension point to allow customisation of build status. Additional data could be sei in the optionalData field where all entries will be serialised starting from the root object.
@nfalco79 nfalco79 force-pushed the feature/JENKINS-76027 branch from a98b9a3 to b89041b Compare August 25, 2025 13:57
@nfalco79 nfalco79 merged commit 09973f9 into master Aug 25, 2025
17 checks passed
@nfalco79 nfalco79 deleted the feature/JENKINS-76027 branch August 25, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants