jenkinsci/git-changelog-plugin

Nullpointer Exception on Firsttime Build

Closed this issue · 7 comments

When you clone a remote Git repo the first time, a Nullpointer Exception occurs in the changelog plugin:

Cloning the remote Git repository
First time build. Skipping changelog.
---
--- Git Changelog ---
---

Creating changelog CHANGELOG.htmljava.lang.NullPointerException
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:187)
	at com.google.common.base.Optional.of(Optional.java:84)
	at se.bjurr.gitchangelog.api.GitChangelogApi.getId(GitChangelogApi.java:480)
	at se.bjurr.gitchangelog.api.GitChangelogApi.getChangelog(GitChangelogApi.java:429)
	at se.bjurr.gitchangelog.api.GitChangelogApi.getChangelog(GitChangelogApi.java:77)
	at se.bjurr.gitchangelog.api.GitChangelogApi.render(GitChangelogApi.java:99)
	at se.bjurr.gitchangelog.api.GitChangelogApi.render(GitChangelogApi.java:123)
	at org.jenkinsci.plugins.gitchangelog.perform.RemoteCallable.call(RemoteCallable.java:189)
	at org.jenkinsci.plugins.gitchangelog.perform.RemoteCallable.call(RemoteCallable.java:29)
	at hudson.remoting.UserRequest.perform(UserRequest.java:207)
	at hudson.remoting.UserRequest.perform(UserRequest.java:53)
	at hudson.remoting.Request$2.run(Request.java:358)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at hudson.remoting.Engine$1$1.run(Engine.java:98)
	at java.base/java.lang.Thread.run(Unknown Source)

How did you configure the plugin?

References:
image
Create File:
image

Is it not just GIT_PREVIOUS_COMMIT that is unset the first time?

it3xl commented

I had a typo in the "From reference" or in "To reference" of the Git Changelog step. Thanks.

@tomasbjerre I'm facing the same NPE when trying to use the plugin from my pipeline Jenkinsfile. I generated the pipeline code from the Snippet Generator. Can you help diagnose my pipeline syntax? Thank you.

env.ARVEST_ANDROID_CHANGELOG = gitChangelog
  from: [
    type: 'COMMIT',
    value: 'GIT_PREVIOUS_SUCCESSFUL_COMMIT'
  ],
  jira: [
    issuePattern: 'ARGO-[0-9]+',
    password: JIRA_PASSWORD,
    server: 'https://clientresourcesinc.atlassian.net/',
    username: JIRA_USERNAME
  ],
  repo: 'https://bitbucket.org/my-organization/repo-name.git',
  returnType: 'STRING',
  template: '''# Changelog for {{repoName}}.

    {{#tags}}
    ## {{name}}
      {{#issues}}
        {{#hasIssue}}
          {{#hasLink}}
    ### {{name}} [{{issue}}]({{link}}) {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}}
          {{/hasLink}}
          {{^hasLink}}
    ### {{name}} {{issue}} {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}}
          {{/hasLink}}
        {{/hasIssue}}
        {{^hasIssue}}
    ### {{name}}
        {{/hasIssue}}

        {{#commits}}
      **{{{messageTitle}}}**

      {{#messageBodyItems}}
       * {{.}}
      {{/messageBodyItems}}

      [{{hash}}](https://bitbucket.org/{{ownerName}}/{{repoName}}/commits/{{hash}}) {{authorName}} *{{commitTime}}*

        {{/commits}}

        {{/issues}}
    {{/tags}}''',
  timeZone: 'CDT',
  to: [type: 'COMMIT', value: 'GIT_COMMIT']

You should change 'GIT_PREVIOUS_SUCCESSFUL_COMMIT' to just GIT_PREVIOUS_SUCCESSFUL_COMMIT
If that is a variable. Same with 'GIT_COMMIT'.

And if that does not help you should open a new issue for your problem. Stating your Jenkins version and plugin version.

Thank you Tomas, that fixed it. Thank you for helping maintain this cool plugin!