Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-70726] Build result scoring skipped on pipeline jobs #65

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vtwaldo21
Copy link

@vtwaldo21 vtwaldo21 commented Jul 21, 2024

Added support for Build Result scoring on pipeline jobs (was always returning 0)
closes #64

https://issues.jenkins.io/browse/JENKINS-70726

Testing done

Verified that jobs were scored based on Build Result when the job was pipeline using the logging feature. Did not regression test that freestyle jobs continue to work.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@vtwaldo21 vtwaldo21 requested a review from a team as a code owner July 21, 2024 06:29
@vtwaldo21
Copy link
Author

oh, i also had a second freebie commit for just some random code-cleanup/typos.

@vtwaldo21 vtwaldo21 changed the title Bugfix/64 buildresult scoring skipped on pipeline jobs Bugfix/64 buildresult scoring skipped on pipeline jobs (#64) Jul 21, 2024
@viceice viceice changed the title Bugfix/64 buildresult scoring skipped on pipeline jobs (#64) buildresult scoring skipped on pipeline jobs Jul 22, 2024
@viceice viceice added the bugfix A PR that fixes a bug - used by Release Drafter label Jul 22, 2024
@viceice viceice changed the title buildresult scoring skipped on pipeline jobs Build result scoring skipped on pipeline jobs Jul 22, 2024
@viceice viceice changed the title Build result scoring skipped on pipeline jobs JENKINS-70726 - Build result scoring skipped on pipeline jobs Jul 22, 2024
@viceice viceice changed the title JENKINS-70726 - Build result scoring skipped on pipeline jobs [JENKINS-70726] Build result scoring skipped on pipeline jobs Jul 22, 2024
@vtwaldo21 vtwaldo21 force-pushed the bugfix/64-buildresult-scoring-skipped-on-pipeline-jobs branch from 3844c32 to 89e9d4f Compare July 24, 2024 17:56
BuildResult scoring always returned 0 for pipeline jobs, this
change hopefully supports both freestyle and pipeline jobs
by properly checking the class type
@vtwaldo21 vtwaldo21 force-pushed the bugfix/64-buildresult-scoring-skipped-on-pipeline-jobs branch from 89e9d4f to 0d1518c Compare July 24, 2024 18:02
WorkflowRun pipelinebuild = null;

if ((subtask instanceof AbstractProject)) {
AbstractProject<?, ?> project = (AbstractProject<?, ?>) subtask;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AbstractProject<?, ?> project = (AbstractProject<?, ?>) subtask;
var project = (AbstractProject<?, ?>) subtask;

Use var where possible

AbstractProject<?, ?> project = (AbstractProject<?, ?>) subtask;
freestylebuild = project.getLastBuild();
} else if (subtask != null) {
Executable qexec = subtask.getOwnerExecutable();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Executable qexec = subtask.getOwnerExecutable();
var qexec = subtask.getOwnerExecutable();

} else if (subtask != null) {
Executable qexec = subtask.getOwnerExecutable();
if (qexec != null && (qexec.getParent() instanceof WorkflowJob)) {
WorkflowJob wfj = (WorkflowJob) qexec.getParent();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
WorkflowJob wfj = (WorkflowJob) qexec.getParent();
var wfj = (WorkflowJob) qexec.getParent();

result = freestylebuild.getResult();
freestylebuild = freestylebuild.getPreviousBuild();
} else if (pipelinebuild != null) {
FlowExecution fexec = pipelinebuild.getExecution();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
FlowExecution fexec = pipelinebuild.getExecution();
var fexec = pipelinebuild.getExecution();

continue;
}

FlowGraphWalker fgw = new FlowGraphWalker(fexec);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
FlowGraphWalker fgw = new FlowGraphWalker(fexec);
var fgw = new FlowGraphWalker(fexec);

FlowGraphWalker fgw = new FlowGraphWalker(fexec);
for (FlowNode fn : fgw) {
if (fn instanceof StepStartNode) {
WorkspaceAction action = (WorkspaceAction) fn.getAction(WorkspaceAction.class);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
WorkspaceAction action = (WorkspaceAction) fn.getAction(WorkspaceAction.class);
var action = (WorkspaceAction) fn.getAction(WorkspaceAction.class);

nodesScore.addScore(node, getScoreForFailure() * scale);
nodeSet.remove(node);
} else if (Result.UNSTABLE == build.getResult()) {
} else if (Result.UNSTABLE == result) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test case to cover code?

@viceice
Copy link
Member

viceice commented Aug 22, 2024

image
Use the re-request review button when done to notify my for another review 🤗

@viceice viceice marked this pull request as draft December 2, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix A PR that fixes a bug - used by Release Drafter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scoring by Build Results always resulting in zero score (JENKINS-70726)
2 participants