bitbucket-push-and-pull-request-plugin icon indicating copy to clipboard operation
bitbucket-push-and-pull-request-plugin copied to clipboard

Job is not being trigerred upon pushing to branch

Open liashukvladyslav opened this issue 5 years ago • 10 comments

Jenkins version 2.249.1 Plugin version 2.5 Bitbucket cloud

Plugin-related settings in the job https://prnt.sc/uzi164

Log output

2020-10-14 23:45:53.948+0000 [id=211]   INFO    i.j.p.b.BitBucketPPRHookReceiver#doIndex: Received x-event-key repo:push from Bitbucket
2020-10-14 23:45:53.953+0000 [id=211]   INFO    i.j.p.b.p.BitBucketPPRPayloadProcessorFactory#createProcessor: Create BitBucketPPRRepositoryCloudPayloadProcessor
2020-10-14 23:45:53.953+0000 [id=211]   INFO    i.j.p.b.o.BitBucketPPRObserverFactory#createObservable: Add BitBucketPPRPushCloudObserver for BitBucketPPREvent [event=repo, action=push]
2020-10-14 23:45:53.953+0000 [id=211]   INFO    i.j.p.b.p.BitBucketPPRRepositoryCloudPayloadProcessor#buildActionForJobs: Instantiate BitBucketPPRRepositoryAction
2020-10-14 23:45:53.954+0000 [id=211]   INFO    i.j.p.b.a.BitBucketPPRRepositoryAction#<init>: Received commit hook notification for branch: staging
2020-10-14 23:45:53.954+0000 [id=211]   INFO    i.j.p.b.a.BitBucketPPRRepositoryAction#<init>: Received commit hook type: branch
2020-10-14 23:45:53.955+0000 [id=211]   INFO    i.j.p.b.BitBucketPPRJobProbe#matchGitScm: Trying to match [email protected]:*******.git<-->https://bitbucket.org/*******
2020-10-14 23:45:53.955+0000 [id=211]   INFO    i.j.p.b.BitBucketPPRJobProbe#matchGitScm: Matched scm
2020-10-14 23:45:53.955+0000 [id=211]   INFO    i.j.p.b.BitBucketPPRTrigger#onPost: Called onPost with BitBucketPPRRepositoryAction
2020-10-14 23:45:53.955+0000 [id=211]   INFO    i.j.p.b.f.r.BitBucketPPRRepositoryTriggerMatcher#matchesAction: BitBucketPPREvent [event=repo, action=push]
2020-10-14 23:45:53.955+0000 [id=211]   INFO    i.j.p.b.f.BitBucketPPRFilterMatcher#getMatchingFilters: Event BitBucketPPREvent [event=repo, action=push] matches trigger filter io.jenkins.plugins.bitbucketpushandpullrequest.filter.repository.BitBucketPPRRepositoryTriggerFilter@2a794170
2020-10-14 23:45:53.955+0000 [id=211]   INFO    i.j.p.b.BitBucketPPRTrigger#onPost: matchingFilters is not null AND is not empty [io.jenkins.plugins.bitbucketpushandpullrequest.filter.repository.BitBucketPPRRepositoryTriggerFilter@2a794170]
2020-10-14 23:45:53.957+0000 [id=211]   INFO    i.j.p.b.BitBucketPPRHookReceiver#doIndex: Response sent.
2020-10-14 23:45:54.049+0000 [id=279]   INFO    i.j.p.b.BitBucketPPRTrigger$1#onPollSuccess: Called onPollSuccess with polling result hudson.scm.PollingResult@299675ff
2020-10-14 23:45:54.050+0000 [id=279]   INFO    i.j.p.b.BitBucketPPRTrigger$1#onPollSuccess: On Poll Success, get cause: BitBucketPPRTriggerCause [bitbucketAction=BitBucketPPRRepositoryAction]
2020-10-14 23:45:54.050+0000 [id=279]   INFO    i.j.p.b.f.r.BitBucketPPRRepositoryPushActionFilter#shouldTriggerBuild: Should trigger build for the bitbucket action: BitBucketPPRRepositoryAction?
2020-10-14 23:45:54.050+0000 [id=279]   INFO    i.j.p.b.BitBucketPPRTrigger#shouldScheduleJob: Should schedule job: false and (polling result has changes: false or trigger also if there arent changes: {2})
2020-10-14 23:45:54.050+0000 [id=279]   INFO    i.j.p.b.f.r.BitBucketPPRRepositoryPushActionFilter#shouldTriggerBuild: Should trigger build for the bitbucket action: BitBucketPPRRepositoryAction?

liashukvladyslav avatar Oct 14 '20 23:10 liashukvladyslav

Hello @liashuk-se , thanks for reporting! Does that happen only after upgrade to Plugin version 2.5 or was it never working for you before?

Could you try to set allowedBranches to staging instead of refs/heads/staging?

I think the problem could be that for the Bitbucket Cloud payload only the branch name, not the refId, is available for matching branches:

{
  "push": {
    "changes": [
      /* ... */
        "new": {
          "name": "feature/do-not-merge", /* => available as "targetBranch" */
           /* ... */
          }
      /* ... */
}

and in BitBucketPPRRepositoryAction:

// ...
  public BitBucketPPRRepositoryAction(@Nonnull BitBucketPPRPayload payload) {
    this.payload = payload;

    // TODO: why??
    scmUrls.add(payload.getRepository().getLinks().getHtml().getHref());

    for (BitBucketPPRChange change : payload.getPush().getChanges()) {
      if (change.getNewChange() != null) {
        this.targetBranchName = change.getNewChange().getName(); // <= targetBranchName is now "staging"
        this.type = change.getNewChange().getType();
        this.repositoryUuid = payload.getRepository().getUuid();
        break;
      }
    }
    // ...
  }
// ...

macghriogair avatar Oct 15 '20 07:10 macghriogair

Does that happen only after upgrade to Plugin version 2.5 or was it never working for you before?

It's first-time using of the plugin

Could you try to set allowedBranches to staging instead of refs/heads/staging?

Already tried, as well as all of options available from the hint

liashukvladyslav avatar Oct 15 '20 14:10 liashukvladyslav

Have you tried triggering the job once manually via Jenkins?

And, do you have more logs after the line:

2020-10-14 23:45:54.050+0000 [id=279] INFO i.j.p.b.f.r.BitBucketPPRRepositoryPushActionFilter#shouldTriggerBuild: Should trigger build for the bitbucket action: BitBucketPPRRepositoryAction?

As per the partial logs it looks like the BitBucketPPRRepositoryPushActionFilter.shouldTriggerBuild returns false due to this line

matches(allowedBranches, bitbucketAction.getTargetBranch(), null);

where bitbucketAction.getTargetBranch() would return "staging" in your case.

macghriogair avatar Oct 23 '20 15:10 macghriogair

Have you tried triggering the job once manually via Jenkins? Yes, I've tried trigger the job manually after installed plugin and configured it as trigger in the job.

Nothing happens.

And, do you have more logs after the line:

Basically two lines after mentioned

2020-10-14 23:45:54.050+0000 [id=279]	INFO	i.j.p.b.f.r.BitBucketPPRRepositoryPushActionFilter#shouldTriggerBuild: Should trigger build for the bitbucket action: BitBucketPPRRepositoryAction?
2020-10-14 23:45:54.050+0000 [id=279]	INFO	i.j.p.b.BitBucketPPRTrigger#shouldScheduleJob: Should schedule job: false and (polling result has changes: false or trigger also if there arent changes: {2})
2020-10-14 23:45:54.050+0000 [id=279]	INFO	i.j.p.b.f.r.BitBucketPPRRepositoryPushActionFilter#shouldTriggerBuild: Should trigger build for the bitbucket action: BitBucketPPRRepositoryAction?

liashukvladyslav avatar Oct 26 '20 16:10 liashukvladyslav

Could you try to leave allowedBranches empty to see if it triggers at all, please?

macghriogair avatar Oct 28 '20 16:10 macghriogair

If allowedBranches left empty, and that's the only entity (no similar configration for master branch at different pipeline, trigger event is making through and executes the job.

2020-10-28 17:15:04.342+0000 [id=257]	INFO	i.j.p.b.BitBucketPPRHookReceiver#doIndex: Received x-event-key repo:push from Bitbucket
2020-10-28 17:15:04.496+0000 [id=257]	INFO	i.j.p.b.p.BitBucketPPRPayloadProcessorFactory#createProcessor: Create BitBucketPPRRepositoryCloudPayloadProcessor
2020-10-28 17:15:04.500+0000 [id=257]	INFO	i.j.p.b.o.BitBucketPPRObserverFactory#createObservable: Add BitBucketPPRPushCloudObserver for BitBucketPPREvent [event=repo, action=push]
2020-10-28 17:15:04.504+0000 [id=257]	INFO	i.j.p.b.p.BitBucketPPRRepositoryCloudPayloadProcessor#buildActionForJobs: Instantiate BitBucketPPRRepositoryAction
2020-10-28 17:15:04.504+0000 [id=257]	INFO	i.j.p.b.a.BitBucketPPRRepositoryAction#<init>: Received commit hook notification for branch: staging
2020-10-28 17:15:04.505+0000 [id=257]	INFO	i.j.p.b.a.BitBucketPPRRepositoryAction#<init>: Received commit hook type: branch
2020-10-28 17:15:04.512+0000 [id=257]	INFO	i.j.p.b.BitBucketPPRJobProbe#matchGitScm: Trying to match git@*******.git<-->https://bitbucket.org/******
2020-10-28 17:15:04.513+0000 [id=257]	INFO	i.j.p.b.BitBucketPPRJobProbe#matchGitScm: Matched scm
2020-10-28 17:15:04.514+0000 [id=257]	INFO	i.j.p.b.BitBucketPPRTrigger#onPost: Called onPost with BitBucketPPRRepositoryAction
2020-10-28 17:15:04.519+0000 [id=257]	INFO	i.j.p.b.f.r.BitBucketPPRRepositoryTriggerMatcher#matchesAction: BitBucketPPREvent [event=repo, action=push]
2020-10-28 17:15:04.520+0000 [id=257]	INFO	i.j.p.b.f.BitBucketPPRFilterMatcher#getMatchingFilters: Event BitBucketPPREvent [event=repo, action=push] matches trigger filter io.jenkins.plugins.bitbucketpushandpullrequest.filter.repository.BitBucketPPRRepositoryTriggerFilter@2ffddcf1
2020-10-28 17:15:04.520+0000 [id=257]	INFO	i.j.p.b.BitBucketPPRTrigger#onPost: matchingFilters is not null AND is not empty [io.jenkins.plugins.bitbucketpushandpullrequest.filter.repository.BitBucketPPRRepositoryTriggerFilter@2ffddcf1]

liashukvladyslav avatar Oct 28 '20 18:10 liashukvladyslav

My job is also not firing when I push a change to my branch. When I set the allowedBranches to "refs/heads/develop" it doesn't fire but when I change it to just "develop" it does fire. Just setting it to develop is too ambiguous, I prefer to point to the specific branch if possible.

madmobilemike avatar Nov 20 '20 15:11 madmobilemike

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 12:04 stale[bot]

Hi @macghriogair , I created push trigger with same configuration for a freestyle job and a pipeline job. Initially both the jobs were triggered on push event. But after some time freestyle job is triggered but pipeline job is not getting trigger. It's giving the following log for pipeline job:

Should trigger build for the bitbucket action: BitBucketPPRRepositoryAction? Jul 25, 2023 12:15:05 PM FINE io.jenkins.plugins.bitbucketpushandpullrequest.common.BitBucketPPRUtils Following allowed branches patterns are set: Dev-1 Jul 25, 2023 12:15:05 PM FINE io.jenkins.plugins.bitbucketpushandpullrequest.common.BitBucketPPRUtils The branchName in action is: Dev-1 Jul 25, 2023 12:15:05 PM FINE io.jenkins.plugins.bitbucketpushandpullrequest.common.BitBucketPPRUtils The environment variables are: null Jul 25, 2023 12:15:05 PM INFO io.jenkins.plugins.bitbucketpushandpullrequest.common.BitBucketPPRUtils lambda$matches$2 Matched branch: Dev-1 Jul 25, 2023 12:15:05 PM FINEST io.jenkins.plugins.bitbucketpushandpullrequest.BitBucketPPRTrigger Should schedule job: true and (polling result has changes: false or trigger also if there aren't changes: false) Jul 25, 2023 12:15:05 PM INFO io.jenkins.plugins.bitbucketpushandpullrequest.filter.repository.BitBucketPPRRepositoryPushActionFilter shouldTriggerBuild Should trigger build for the bitbucket action: BitBucketPPRRepositoryAction?

But when I am checking the checkbox "Trigger also if nothing has changed in the repo".. pipeline is getting trigger upon push action in the allowed branch.

Any suggestion? (plugin version is - 2.8.3, I am using bitbucket cloud and jenkins version is 2.401.1)

pratimamaiti13 avatar Jul 25 '23 11:07 pratimamaiti13

@liashukvladyslav Hello! I am not able to reproduce the error. Did you put your target branch in the allowed branches field or the source branch?

julioc-p avatar Sep 20 '24 12:09 julioc-p