Skip to content

Conversation

@jmairboeck
Copy link

This plugin uses RequestImpl internals directly (casting StaplerRequest), which broke when Stapler was updated to EE 9 in jenkinsci/stapler#482.

This change also updates dependencies to current versions where needed.

The access modifier checker had to be disabled because this uses some Messages from the core.

Testing done

Unit tests ran successfully.

I installed the locally built plugin in our Jenkins instance (running version 2.504.1) and was able to successfully update the job configuration of the jobs which are using this. This failed before with a ClassCastException in TemplateStaplerRequestWrapper.

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 demonstrate the feature works or the issue is fixed

This plugin uses RequestImpl internals directly (casting StaplerRequest), which
broke when Stapler was updated to EE 9 in
jenkinsci/stapler#482.

This change also updates dependencies to current versions where needed.

The access modifier checker had to be disabled because this uses some Messages
from the core.
Comment on lines -251 to -393
/**
* Returns the last build.
*
* @return the build or null
*/
@SuppressWarnings(UNUSED)
@CheckForNull
@Exported
public Run getLastBuild() {
Run retVal = null;
for (Job job : getAllJobs()) {
retVal = takeLast(retVal, job.getLastBuild());
}
return retVal;
}

/**
* Returns the oldest build in the record.
*
* @return the build or null
*/
@SuppressWarnings(UNUSED)
@CheckForNull
@Exported
public Run getFirstBuild() {
Run retVal = null;
for (Job job : getAllJobs()) {
Run run = job.getFirstBuild();
if (run != null && (retVal == null || run.getTimestamp().before(retVal.getTimestamp()))) {
retVal = run;
}
}
return retVal;
}

/**
* Returns the last successful build, if any. Otherwise null. A successful build would include
* either {@link Result#SUCCESS} or {@link Result#UNSTABLE}.
*
* @return the build or null
* @see #getLastStableBuild()
*/
@SuppressWarnings(UNUSED)
@CheckForNull
@Exported
public Run getLastSuccessfulBuild() {
Run retVal = null;
for (Job job : getAllJobs()) {
retVal = takeLast(retVal, job.getLastSuccessfulBuild());
}
return retVal;
}

/**
* Returns the last build that was anything but stable, if any. Otherwise null.
*
* @return the build or null
* @see #getLastSuccessfulBuild
*/
@SuppressWarnings(UNUSED)
@CheckForNull
@Exported
public Run getLastUnsuccessfulBuild() {
Run retVal = null;
for (Job job : getAllJobs()) {
retVal = takeLast(retVal, job.getLastUnsuccessfulBuild());
}
return retVal;
}

/**
* Returns the last unstable build, if any. Otherwise null.
*
* @return the build or null
* @see #getLastSuccessfulBuild
*/
@SuppressWarnings(UNUSED)
@CheckForNull
@Exported
public Run getLastUnstableBuild() {
Run retVal = null;
for (Job job : getAllJobs()) {
retVal = takeLast(retVal, job.getLastUnstableBuild());
}
return retVal;
}

/**
* Returns the last stable build, if any. Otherwise null.
*
* @return the build or null
* @see #getLastSuccessfulBuild
*/
@SuppressWarnings(UNUSED)
@CheckForNull
@Exported
public Run getLastStableBuild() {
Run retVal = null;
for (Job job : getAllJobs()) {
retVal = takeLast(retVal, job.getLastStableBuild());
}
return retVal;
}

/**
* Returns the last failed build, if any. Otherwise null.
*
* @return the build or null
*/
@SuppressWarnings(UNUSED)
@CheckForNull
@Exported
public Run getLastFailedBuild() {
Run retVal = null;
for (Job job : getAllJobs()) {
retVal = takeLast(retVal, job.getLastFailedBuild());
}
return retVal;
}

/**
* Returns the last completed build, if any. Otherwise null.
*
* @return the build or null
*/
@SuppressWarnings(UNUSED)
@CheckForNull
@Exported
public Run getLastCompletedBuild() {
Run retVal = null;
for (Job job : getAllJobs()) {
retVal = takeLast(retVal, job.getLastCompletedBuild());
}
return retVal;
}

@CheckForNull
private Run takeLast(Run run1, Run run2) {
if (run2 != null && (run1 == null || run2.getTimestamp().after(run1.getTimestamp()))) {
return run2;
}
return run1;
}
Copy link
Author

Choose a reason for hiding this comment

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

I think that these methods aren't needed any more. They seem to be replaced with jenkinsci/cloudbees-folder-plugin#87. (They would at least require some changes to still build.)

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Thanks!

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