jenkinsci / violation-comments-to-gitlab-plugin

Comments GitLab merge requests with static code analyzer findings.
https://plugins.jenkins.io/violation-comments-to-gitlab
MIT License
20 stars 4 forks source link

Getting null pointer exception on comment #23

Closed Arbuzov closed 4 years ago

Arbuzov commented 4 years ago

Plugin version 2.31 Jenkins version 2.138.3 Gitlab 10.7.3 ce

Pipeline command

        step([
          $class: 'ViolationsToGitLabRecorder',
          config: [
            gitLabUrl: 'https://mygitlabserver/',
            projectId: 'projectgroup/project-name',
            mergeRequestIid: env.gitlabMergeRequestIid,
            //createCommentWithAllSingleFileComments: true,
            createSingleFileComments: true,
            //commentOnlyChangedContent: true,
            commentOnlyChangedFiles: true,
            minSeverity: 'INFO',
            maxNumberOfViolations: 99999,
            enableLogging: true,
            apiTokenCredentialsId: 'jenkins-violations-secret',
            apiTokenPrivate: true,
            authMethodHeader: true,
            ignoreCertificateErrors: true,
            keepOldComments: false,
            commentTemplate: """___
**Reporter**: {{violation.reporter}}{{#violation.rule}}

**Rule**: {{violation.rule}}{{/violation.rule}}

**Severity**: {{violation.severity}}

**File**: {{violation.file}} L{{violation.startLine}}{{#violation.source}}

**Source**: {{violation.source}}{{/violation.source}}

> {{violation.message}}
""",
            violationConfigs: [
              [ pattern: '.*checkstyle\\.xml$', parser: 'CHECKSTYLE', reporter: 'Checkstyle' ]
            ]
          ]
        ])

Stack trace during the build

java.lang.NullPointerException
    at se.bjurr.violations.comments.gitlab.lib.GitLabCommentsProvider.createSingleFileComment(GitLabCommentsProvider.java:161)
    at se.bjurr.violations.comments.lib.CommentsCreator.createSingleFileComments(CommentsCreator.java:147)
    at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:71)
    at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:38)
    at se.bjurr.violations.comments.gitlab.lib.ViolationCommentsToGitLabApi.toPullRequest(ViolationCommentsToGitLabApi.java:175)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer.doPerform(JvctglPerformer.java:160)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:268)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:256)
    at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3052)
    at hudson.remoting.UserRequest.perform(UserRequest.java:212)
    at hudson.remoting.UserRequest.perform(UserRequest.java:54)
    at hudson.remoting.Request$2.run(Request.java:369)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
tomasbjerre commented 4 years ago

Does it happen with every MR? Or just with one of them?

Den tis 8 okt. 2019 10:38Arbuzov Sergey notifications@github.com skrev:

Plugin version 2.31 Jenkins version 2.138.3

Pipeline command ` step([ $class: 'ViolationsToGitLabRecorder', config: [ gitLabUrl: 'https://mygitlabserver/', projectId: 'projectgroup/project-name', mergeRequestIid: env.gitlabMergeRequestIid, //createCommentWithAllSingleFileComments: true, createSingleFileComments: true, //commentOnlyChangedContent: true, commentOnlyChangedFiles: true, minSeverity: 'INFO', maxNumberOfViolations: 99999, enableLogging: true, apiTokenCredentialsId: 'jenkins-violations-secret', apiTokenPrivate: true, authMethodHeader: true, ignoreCertificateErrors: true, keepOldComments: false, commentTemplate: """___ Reporter: {{violation.reporter}}{{#violation.rule}}

Rule: {{violation.rule}}{{/violation.rule}}

Severity: {{violation.severity}}

File: {{violation.file}} L{{violation.startLine}}{{#violation.source}}

Source: {{violation.source}}{{/violation.source}}

{{violation.message}} """, violationConfigs: [ [ pattern: '.*checkstyle.xml$', parser: 'CHECKSTYLE', reporter: 'Checkstyle' ] ] ] ]) `

java.lang.NullPointerException at se.bjurr.violations.comments.gitlab.lib.GitLabCommentsProvider.createSingleFileComment(GitLabCommentsProvider.java:161) at se.bjurr.violations.comments.lib.CommentsCreator.createSingleFileComments(CommentsCreator.java:147) at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:71) at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:38) at se.bjurr.violations.comments.gitlab.lib.ViolationCommentsToGitLabApi.toPullRequest(ViolationCommentsToGitLabApi.java:175) at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer.doPerform(JvctglPerformer.java:160) at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:268) at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:256) at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3052) at hudson.remoting.UserRequest.perform(UserRequest.java:212) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:369) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jenkinsci/violation-comments-to-gitlab-plugin/issues/23?email_source=notifications&email_token=AADLKE5GWXYZIVRRDDIHPZDQNRBHLA5CNFSM4I6OVJIKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HQJAFTA, or mute the thread https://github.com/notifications/unsubscribe-auth/AADLKE2GQYGCNOUH66HZGX3QNRBHLANCNFSM4I6OVJIA .

tomasbjerre commented 4 years ago

Releasing 2.32 that should give a clearer error, but still not solving the issue.

Arbuzov commented 4 years ago

It happens with every MR

tomasbjerre commented 4 years ago

Did you try the new version? What is the new error?

MarcJose commented 4 years ago

The current error seems to be the same (on version 2.32):

04:37:49 ---
04:37:49 --- Violation Comments to GitLab ---
04:37:49 ---
04:37:49 gitLabUrl: null
04:37:49 projectId: 
04:37:49 mergeRequestIid: 
04:37:49 apiTokenCredentialsId: true
04:37:49 ignoreCertificateErrors: false
04:37:49 apiTokenPrivate: false
04:37:49 authMethodHeader: false
04:37:49 createCommentWithAllSingleFileComments: true
04:37:49 createSingleFileComments: false
04:37:49 commentOnlyChangedContent: false
04:37:49 commentOnlyChangedFiles: false
04:37:49 maxNumberOfViolations:null
04:37:49 minSeverity: WARN
04:37:49 keepOldComments: false
04:37:49 shouldSetWip: true
04:37:49 commentTemplate: 
04:37:49 proxyUri: 
04:37:49 proxyCredentialsId: no
04:37:49 CHECKSTYLE with pattern .*/build/reports/checkstyle/.*\.html$
04:37:49 CPD with pattern .*/build/reports/cpd/.*\.text$
04:37:49 FINDBUGS with pattern .*/build/reports/spotbugs/.*\.html$
04:37:49 PMD with pattern .*/build/reports/pmd/.*\.html$
04:37:49 Running Violation Comments To GitLab
04:37:49 Merge request: 
04:37:49 Workspace: /var/lib/jenkins/workspace/group/project
04:37:49 Found 0 violations from ViolationConfig [pattern=.*/build/reports/checkstyle/.*\.html$, parser=CHECKSTYLE, reporter=].
04:37:49 Found 0 violations from ViolationConfig [pattern=.*/build/reports/cpd/.*\.text$, parser=CPD, reporter=].
04:37:49 Found 0 violations from ViolationConfig [pattern=.*/build/reports/spotbugs/.*\.html$, parser=FINDBUGS, reporter=].
04:37:49 Found 0 violations from ViolationConfig [pattern=.*/build/reports/pmd/.*\.html$, parser=PMD, reporter=].
04:37:49 Will comment PR null  
04:37:49 java.lang.NumberFormatException: For input string: ""
04:37:49    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
04:37:49    at java.base/java.lang.Integer.parseInt(Integer.java:662)
04:37:49    at java.base/java.lang.Integer.parseInt(Integer.java:770)
04:37:49    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer.doPerform(JvctglPerformer.java:115)
04:37:49    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:268)
04:37:49    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:256)
04:37:49    at hudson.FilePath.act(FilePath.java:1078)
04:37:49    at hudson.FilePath.act(FilePath.java:1061)
04:37:49    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer.jvctsPerform(JvctglPerformer.java:255)
04:37:49    at org.jenkinsci.plugins.jvctgl.ViolationsToGitLabRecorder.perform(ViolationsToGitLabRecorder.java:62)
04:37:49    at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:79)
04:37:49    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
04:37:49    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
04:37:49    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
04:37:49    at hudson.model.Build$BuildExecution.post2(Build.java:186)
04:37:49    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
04:37:49    at hudson.model.Run.execute(Run.java:1840)
04:37:49    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
04:37:49    at hudson.model.ResourceController.execute(ResourceController.java:97)
04:37:49    at hudson.model.Executor.run(Executor.java:429)
04:37:49 
04:37:49 Failed to update Gitlab commit status: No credentials found for credentialsId: 
tomasbjerre commented 4 years ago

No that is very different stacktrace. Now you are missing project and merge request iid:

04:37:49 gitLabUrl: null
04:37:49 projectId: 
04:37:49 mergeRequestIid: 
04:37:49 apiTokenCredentialsId: true
MarcJose commented 4 years ago

hmm shouldnt it use the global one by default? Alright my bad actually... I looked at the wrong fields sorry.

Arbuzov commented 4 years ago

Sorry. Had some issues with the hardware. This is the new stacktrace

INFO Asking GitLabCommentsProvider to comment:
Post stage
[Pipeline] sh
INFO Checkstyle WARN jshint.W064 api/routes/sites/{site_id}.js 11 
java.lang.NullPointerException: diffRefs is null for MR with Iid 320 in projectId 780
    at java.util.Objects.requireNonNull(Objects.java:228)
    at se.bjurr.violations.comments.gitlab.lib.GitLabCommentsProvider.createSingleFileComment(GitLabCommentsProvider.java:172)
    at se.bjurr.violations.comments.lib.CommentsCreator.createSingleFileComments(CommentsCreator.java:147)
    at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:71)
    at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:38)
    at se.bjurr.violations.comments.gitlab.lib.ViolationCommentsToGitLabApi.toPullRequest(ViolationCommentsToGitLabApi.java:176)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer.doPerform(JvctglPerformer.java:160)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:268)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:256)
    at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3052)
    at hudson.remoting.UserRequest.perform(UserRequest.java:212)
    at hudson.remoting.UserRequest.perform(UserRequest.java:54)
    at hudson.remoting.Request$2.run(Request.java:369)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
tomasbjerre commented 4 years ago

What is the response of this? https://mygitlabserver/api/v4/projects/780/merge_requests/320/changes

Arbuzov commented 4 years ago

Please find attached all response in the archive changes.json.zip

tomasbjerre commented 4 years ago

Released 2.34 now. Should fix the problem. Available in the update site within hours.

Arbuzov commented 4 years ago

I am afraid not yet.

INFO Asking GitLabCommentsProvider to comment:
INFO Checkstyle WARN jshint.W064 api/routes/sites/{site_id}.js 11 
java.lang.NullPointerException: diffRefs is null for MR with Iid 320 in projectId 780
    at java.util.Objects.requireNonNull(Objects.java:228)
    at se.bjurr.violations.comments.gitlab.lib.GitLabCommentsProvider.createSingleFileComment(GitLabCommentsProvider.java:177)
    at se.bjurr.violations.comments.lib.CommentsCreator.createSingleFileComments(CommentsCreator.java:147)
    at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:71)
    at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:38)
    at se.bjurr.violations.comments.gitlab.lib.ViolationCommentsToGitLabApi.toPullRequest(ViolationCommentsToGitLabApi.java:176)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer.doPerform(JvctglPerformer.java:160)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:268)
    at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$2.invoke(JvctglPerformer.java:256)
    at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3052)
    at hudson.remoting.UserRequest.perform(UserRequest.java:212)
    at hudson.remoting.UserRequest.perform(UserRequest.java:54)
    at hudson.remoting.Request$2.run(Request.java:369)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

changes2.json.zip

Full log in zip to avoid search indexing

full.log.zip

tomasbjerre commented 4 years ago

Strange, what is the response of this? https://mygitlabserver/api/v4/projects/780/merge_requests/320

Arbuzov commented 4 years ago

See attached 320.zip

tomasbjerre commented 4 years ago

The problem is that diff_refs is missing in your version of Gitlab. Not sure why.

In Gitlab.com it is there: https://gitlab.com/api/v4/projects/2732496/merge_requests/1 and also in /changes: https://gitlab.com/api/v4/projects/2732496/merge_requests/1/changes

It should also be there according to the docs: https://docs.gitlab.com/ce/api/merge_requests.html#get-single-mr https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr

tomasbjerre commented 4 years ago

I tried Gitlab 10.7.3 and I can also see that diff_refs is missing. Could be a bug in that version. I would suggest upgrading Gitlab.

Arbuzov commented 4 years ago

Thanks a lot for the clarification. I will try to update my Gitlab next Monday and write the result here.

Arbuzov commented 4 years ago

I updated my gitlab instance to 12.3.5 and the issue was fixed. Thanks a lot for your help