jenkins-gitlab-merge-request-builder-plugin icon indicating copy to clipboard operation
jenkins-gitlab-merge-request-builder-plugin copied to clipboard

GitlabMergeRequestWrapper exception

Open hicolour opened this issue 9 years ago • 1 comments

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

hicolour avatar Sep 24 '14 13:09 hicolour

Is this issue fixed?

AndreaGiardini avatar Sep 18 '15 11:09 AndreaGiardini