Skip to content

In WorkflowJob, fails to delete "build started" comment and add "build success/failure" comment #135

@ghost

Description

This is with an hpi build from the commit b2be679 manually installed into a jenkins docker container.

The initial build comment is successfully posted, but fails to be deleted once the workflow job completes. I've traced this to the following scenario:

  1. StashPullRequestBuilder run is invoked
  2. StashRepository init is invoked followed by all methods to check if build should be triggered
  3. StashRepository recognizes build should be triggered, posts "build started" comment
  4. StashBuilds onStarted is invoked
  5. StashRespository client (StashApiClient) is finalized
  6. WorkflowRun finish is invoked with SUCCESS result
  7. StashBuilds onCompleted is invoked
  8. StashRespository tries to delete "build started" comment, but StashRespository client has already been finalized and so is null

I'm confused as to why StashRespository.client gets finalized before the StashRespository object itself is finalized. I see nowhere where StashRespository is getting set to null, so StashRespository should still have a reference to the client created in the StashRepository.init method, should it not?

I was able to fix this by simply always allocating a new StashApiClient when needed. This is inefficient so I'd much rather understand why the StashApiClient is being garbage collected so soon.

Dec 20, 2017 4:41:01 AM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository isBuildTarget
INFO: Building PR: 1
Dec 20, 2017 4:41:01 AM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository addFutureBuildTasks
INFO: TETO-test-PR client: stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient@613d0a49
Dec 20, 2017 4:41:01 AM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository getAdditionalParameters
INFO: TETO-test-PR client: stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient@613d0a49
Dec 20, 2017 4:41:01 AM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository postBuildStartCommentTo
INFO: TETO-test-PR client: stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient@613d0a49
Dec 20, 2017 4:41:02 AM stashpullrequestbuilder.stashpullrequestbuilder.StashBuildListener onStarted
INFO: BuildListener onStarted called.
Dec 20, 2017 4:41:02 AM stashpullrequestbuilder.stashpullrequestbuilder.StashBuilds onStarted
INFO: client: stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient@613d0a49
Dec 20, 2017 4:41:07 AM stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient finalize
INFO: StashApiClient finalize
Dec 20, 2017 4:41:13 AM org.jenkinsci.plugins.workflow.job.WorkflowRun finish
INFO: TETO-test-PR #14 completed: SUCCESS
Dec 20, 2017 4:41:13 AM stashpullrequestbuilder.stashpullrequestbuilder.StashBuilds onCompleted
INFO: client: null
Dec 20, 2017 4:41:13 AM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository deletePullRequestComment
INFO: TETO-test-PR pullRequestId: 1, commentId: 689695
Dec 20, 2017 4:41:13 AM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository deletePullRequestComment
INFO: TETO-test-PR this.client: null
Dec 20, 2017 4:41:13 AM stashpullrequestbuilder.stashpullrequestbuilder.StashRepository deletePullRequestComment
INFO: TETO-test-PR client: null
Dec 20, 2017 4:41:13 AM hudson.model.listeners.RunListener report
WARNING: RunListener failed
java.lang.NullPointerException
	at stashpullrequestbuilder.stashpullrequestbuilder.StashRepository.deletePullRequestComment(StashRepository.java:186)
	at stashpullrequestbuilder.stashpullrequestbuilder.StashBuilds.onCompleted(StashBuilds.java:63)
	at stashpullrequestbuilder.stashpullrequestbuilder.StashBuildListener.onCompleted(StashBuildListener.java:34)
	at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:211)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:664)
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions