Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-64883

Bitbucket triggers don't actually start Jenkins jobs

XMLWordPrintable

      We have a problem that Bitbucket triggers don't actually start Jenkins jobs. This is what we are seeing.

      When a pull request is merged in Bitbucket, Bitbucket sends a webhook to Jenkins. Jenkins receives the webhook and prints the following in the log:

      Feb 16, 2021 12:16:18 PM FINE com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer
      Received refs changed event from repo: <project>/<repo>
      Feb 16, 2021 12:16:18 PM FINE com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer
      Triggering <job>
      

      So far, everything looks fine.

      However, <job> never seems to be started and nothing more of interest appears in the log.

      Since "Triggering " is displayed in the log, I guess we must end up in the following code:

      Jenkins.get().getAllItems(ParameterizedJobMixIn.ParameterizedJob.class)
              .stream()
              .map(BitbucketWebhookConsumer::toTriggerDetails)
              .filter(Optional::isPresent)
              .map(Optional::get)
              .filter(triggerDetails -> hasMatchingRepository(refChangedDetails, triggerDetails.getJob()))
              .peek(triggerDetails -> LOGGER.fine("Triggering " + triggerDetails.getJob().getFullDisplayName()))
              .forEach(triggerDetails -> triggerDetails.getTrigger().trigger(requestBuilder.build()));
      

      Moreover, trigger must be called on the trigger after the logging, which I suspect is this method:

      @Override
      public void trigger(BitbucketWebhookTriggerRequest triggerRequest) {
          SCMTriggerItem triggerItem = asSCMTriggerItem(job);
          if (triggerItem != null) {
              getDescriptor().schedule(job, triggerItem, triggerRequest);
          }
      }
      

      So my guess is that triggerItem for some reason becomes null. And nothing actually happends after the logging.

      In what circumstances can triggerItem be null?

      Any suggestions how we can investigate further?

      When trying different workarounds like saving the job again and running it manually one time, the trigger started working. But that didnt't seem to work all of the time. (And we have many jobs with this problem.) And I'm not certain what exactly in the workaround process made it start working. Manual trigger of the job works as expected.

      Some details about our environment:

      • The job that is triggered is a Pipeline job.
      • The job was previously triggered by another job, and had no trigger by itself.

            Unassigned Unassigned
            rickardblindberg Rickard
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: