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

Don't let the build fail if the commit doesn't exist in upstream #111

Merged
merged 3 commits into from
Apr 9, 2016

Conversation

kohsuke
Copy link
Member

@kohsuke kohsuke commented Mar 7, 2016

PR builds and other merge activities can create a new tip of the repository that's not in the github repository. This plugin causes the build to fail in such a case today, which is undesirable. We'd rather just have the build to succeed without a commit status.

This is the stack trace you get when that happens:

ERROR: Step ‘Set build status on GitHub commit’ aborted due to exception: 
java.io.FileNotFoundException: {"message":"No commit found for SHA: bb077596591672c8348ace0f8ddb2a13df2e0892","documentation_url":"https://developer.github.com/v3/repos/statuses/"}
    at org.kohsuke.github.Requester.handleApiError(Requester.java:527)
    at org.kohsuke.github.Requester._to(Requester.java:257)
    at org.kohsuke.github.Requester.to(Requester.java:203)
    at org.kohsuke.github.GHRepository.createCommitStatus(GHRepository.java:854)
    at com.cloudbees.jenkins.GitHubCommitNotifier.updateCommitStatus(GitHubCommitNotifier.java:142)
    at com.cloudbees.jenkins.GitHubCommitNotifier.perform(GitHubCommitNotifier.java:111)
    at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:75)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:795)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:736)
    at hudson.model.Build$BuildExecution.post2(Build.java:185)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:681)
    at hudson.model.Run.execute(Run.java:1766)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:408)
Caused by: java.io.FileNotFoundException: https://api.github.com/repos/cloudbees/blueocean/statuses/bb077596591672c8348ace0f8ddb2a13df2e0892
    at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:240)
    at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
    at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
    at org.kohsuke.github.Requester.parse(Requester.java:483)
    at org.kohsuke.github.Requester._to(Requester.java:236)
    ... 14 more

Review on Reviewable

// PR builds and other merge activities can create a merge commit that
// doesn't exist in the upstream. Don't let the build fail
// TODO: ideally we'd like other plugins to designate a commit to put the status update to
listener.getLogger().println("Commit doesn't exist in " +
Copy link
Member

Choose a reason for hiding this comment

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

+ on newline to pass checkstyle

@michaelneale
Copy link
Member

🐝 one checkstyle violation is fixed.

@KostyaSha
Copy link
Member

  1. no associated jira issue
  2. This changes the strategy of publisher that is totally wrong. Such error can appear because of wrong permissions and then it should fail. If you want special handling, then introduce error handler i.e. like https://github.com/jenkinsci/github-integration-plugin/blob/master/github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/PublisherErrorHandler.java
    👎

@kohsuke
Copy link
Member Author

kohsuke commented Mar 8, 2016

Note that I'm only catching FileNotFoundException so that it can differentiate other configuration errors from "no such commit" error

@KostyaSha
Copy link
Member

What error is used when user has no permissions to repository at all?

@kohsuke
Copy link
Member Author

kohsuke commented Mar 8, 2016

Generic IOExcception is used for anything but 404 in github-api

@jenkinsadmin
Copy link
Member

Thank you for this pull request! Please check this document for how the Jenkins project handles pull requests.

@kohsuke
Copy link
Member Author

kohsuke commented Mar 8, 2016

I created JENKINS-33371 as per your request

@@ -52,6 +55,8 @@
private final String resultOnFailure;
private static final Result[] SUPPORTED_RESULTS = {FAILURE, UNSTABLE, SUCCESS};

private static final Logger LOGGER = Logger.getLogger(GitHubCommitNotifier.class.getName());
Copy link
Member

Choose a reason for hiding this comment

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

use org.slf4j.Logger

@lanwen
Copy link
Member

lanwen commented Mar 8, 2016

think its ok to handle exception with message and not fail the build.
Please remove UnusedImports: Unused import - java.util.logging.Level. and change logger class and ill will merge it

Also please squash dummy commits such as 'sonar, checkstyle fixes' (squashing all be good too)

@KostyaSha
Copy link
Member

think its ok to handle exception with message and not fail the build.

Not really.

  1. First question would be where notifier extracting commit. If it come from push notification, then it may be not correct and then github-plugin should be fixed at all.
    -- Builder can set Pending, then publisher fail and GH will have wrong status.
  2. This is the strategy: fail on errors, skip errors silently. It should be configurable. Either people will PR changes every time or would report bugs for this traces.
  3. Seems Builder forgotten again.

@KostyaSha
Copy link
Member

  1. First question would be where notifier extracting commit. If it come from push notification, then it may be not correct and then github-plugin should be fixed at all.

Found, that's org.jenkinsci.plugins.github.util.BuildDataHelper#getCommitSHA1 that extracts commit from BuildData. AFAIR BuildData stores sha1 for commit that was defined in checkout section. So any GIT scm features shouldn't change initial commit. AFAIR git SCM design (and BuildData?) has real and effective hashes.

Push trigger fully relies on git scm and git scm should provide correct hashes. Would be glad to hear real example and hash changes situation for git scm.

@KostyaSha
Copy link
Member

hudson.plugins.git.util.BuildData#buildsByBranchName:

    public Map<String, Build> buildsByBranchName = new HashMap<String, Build>();

-> hudson.plugins.git.util.Build#marked should be right commit, right?

@lanwen
Copy link
Member

lanwen commented Mar 8, 2016

This builder should be splitted to 3 parts - the hash finder, status and message logic and the result handler (of plugin itself), so now build-safe behaviour can be applied

@KostyaSha
Copy link
Member

@kohsuke please try change BuilDataHelper to use

---        final Revision lastBuildRevision = buildData.getLastBuiltRevision();
+++        final Revision lastBuildRevision = buildData.lastBuild.marked;

@KostyaSha
Copy link
Member

@lanwen absent commit is gitscm or github plugins bug or force push. Force push of course should fail the build as commit doesn't exist anymore and for example pushing tags after it makes no sense.

@kohsuke
Copy link
Member Author

kohsuke commented Mar 8, 2016

Added what Kostya wanted in another commit and squashed the original one.

@KostyaSha
Copy link
Member

@kohsuke does that work? Please remove try then as it would be bug in git plugins. GH commit kicks build and it should exist, either build should be failed.

@KostyaSha
Copy link
Member

cc @oleg-nenashev as BuildDataHelper seems his class

@KostyaSha
Copy link
Member

If try would be removed back, then 👍 as i think it was initial bug on using wrong commits because BuilData design is to crazy for understanding.

@@ -73,6 +73,7 @@
@Override
protected void before() throws Throwable {
when(data.getLastBuiltRevision()).thenReturn(rev);
data.lastBuild = new hudson.plugins.git.util.Build(rev,rev,0,Result.SUCCESS);
Copy link
Member

Choose a reason for hiding this comment

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

please use imports

Copy link
Member

Choose a reason for hiding this comment

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

and spaces (even if checkstyle doesn't cover test classes).

@lanwen
Copy link
Member

lanwen commented Mar 9, 2016

@michaelneale
Copy link
Member

bump - I guess the remaining changes are to fix the import - is that all?
(whilst this won't fail the build, it won;t correctly set the status of the actual commit what was merge validated).

@lanwen
Copy link
Member

lanwen commented Apr 7, 2016

import + logger. Will fix that on the weekend by myself

@lanwen lanwen merged commit 25d7939 into master Apr 9, 2016
@lanwen lanwen deleted the failed-update branch April 9, 2016 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants