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

Bitbucket triggers don't actually start Jenkins jobs

      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.

          [JENKINS-64883] Bitbucket triggers don't actually start Jenkins jobs

          Rickard added a comment -

          JENKINS-60649 sounds like a similar issue.

          Rickard added a comment - JENKINS-60649 sounds like a similar issue.

          Rickard added a comment -

          I entered the wrong link before.

          Rickard added a comment - I entered the wrong link before.

          Rickard added a comment -

          It might also be that the trigger actually works, but the job is not started becasue Jenkins thinks that nothing has changed.

          The above mentioned result is also obtained if a job is disabled for example.

          Rickard added a comment - It might also be that the trigger actually works, but the job is not started becasue Jenkins thinks that nothing has changed. The above mentioned result is also obtained if a job is disabled for example.

          I think Rickard comments makes a lot of sense. I was able to replicate this problem and if I delete the build history for the job the trigger actually works. I am using a trigger when a pull request is created and this problem hapens consistently. Is there a workaround besides deleting the job? 

          Gerardo Molina added a comment - I think Rickard comments makes a lot of sense. I was able to replicate this problem and if I delete the build history for the job the trigger actually works. I am using a trigger when a pull request is created and this problem hapens consistently. Is there a workaround besides deleting the job? 

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

              Created:
              Updated: