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

GitlabMergeRequestWrapper exception #86

Open
hicolour opened this Issue Sep 24, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@hicolour

hicolour commented Sep 24, 2014

Some of the MRs are causing exception and the root cause is 'latestCommit:null'

What's worst this exception is causing stop processing of all other MRs

java.lang.NullPointerException
    at org.jenkinsci.plugins.gitlab.GitlabMergeRequestWrapper.check(GitlabMergeRequestWrapper.java:113)
    at org.jenkinsci.plugins.gitlab.GitlabRepository.check(GitlabRepository.java:83)
    at org.jenkinsci.plugins.gitlab.GitlabRepository.check(GitlabRepository.java:65)

Problem in the source code is this if-else statements

            if (lastJenkinsNote == null) {
                _logger.info("Latest note from Jenkins is null");
                _shouldRun = true;
            } else if (latestCommit == null) {

and last if

   if (_shouldRun) {
                _logger.info("Build is supposed to run");
                _mergeRequestStatus.setLatestCommitOfMergeRequest(_id.toString(), latestCommit.getId());
            }

I will try to make pull request with quick fix for this issue.

        try {
            GitlabAPI api = _builder.getGitlab().get();
            GitlabNote lastJenkinsNote = getJenkinsNote(gitlabMergeRequest, api);
            GitlabCommit latestCommit = getLatestCommit(gitlabMergeRequest, api);

            _logger.log(Level.SEVERE, "MR: " + _mergeRequestStatus + ", id:"+_id+", latestCommit:"+latestCommit);

            if (lastJenkinsNote == null) {
                _logger.info("Latest note from Jenkins is null");
                _shouldRun = true;
            } else if (latestCommit == null) {
                _logger.log(Level.SEVERE, "Failed to determine the lastest commit for merge request {" + gitlabMergeRequest.getId() + "}. This might be caused by a stalled MR in gitlab.");
                return;
            } else {
                _logger.info("Latest note from Jenkins: " + lastJenkinsNote.getId().toString());
                _shouldRun = latestCommitIsNotReached(latestCommit);
                _logger.info("Latest commit: " + latestCommit.getId());
            }
            if (_shouldRun) {
                _logger.info("Build is supposed to run");
                _mergeRequestStatus.setLatestCommitOfMergeRequest(_id.toString(), latestCommit.getId());
            }
        } catch (IOException e) {
            _logger.log(Level.SEVERE, "Failed to fetch commits for Merge Request " + gitlabMergeRequest.getId());
            return;
        }

Reproduced on 7.2 / 7.3

@AndreaGiardini

This comment has been minimized.

Show comment
Hide comment
@AndreaGiardini

AndreaGiardini Sep 18, 2015

Contributor

Is this issue fixed?

Contributor

AndreaGiardini commented Sep 18, 2015

Is this issue fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment