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

Pipeline Jobs Don't Respond to Webhook Events Upon Creation

XMLWordPrintable

      Jenkins pipeline jobs fail to trigger via webhook events automatically and require a manual build using the "Build Now" option for builds to be triggered. This issue seems to affect only pipeline jobs, as multibranch jobs remain unaffected. While the problem is not exclusively tied to the use of Job DSL, using Job DSL increases the frequency of its occurrence. I'll explain the details below.

      When working with Jenkins pipeline jobs, I frequently encounter an issue where the webhook becomes unregistered on the Jenkins side, causing it to stop responding to pull request and push events. I have confirmed that the webhook exists in Bitbucket and that triggers are being sent correctly. Manually starting a build on the affected job temporarily resolves the issue, and triggers begin working again. However, after some time, the problem reoccurs.

      Eventually, I noticed that the failures coincide with the execution of our Job DSL seed job, which runs once a day. It seems that running the Job DSL reconfigures the config.xml for the job, leading to the issue. Initially, I suspected the Job DSL itself was the root cause. To test this, I created a new pipeline job manually through the UI and observed the same behavior. It appears that the webhook is only initialized during the first build of a job. Therefore, while the issue surfaces more frequently when the Job DSL is executed, it seems to be related to webhook registration during the creation of a new job.

      Below is the config.xml file from a broken job after running the seed job. Sensitive information has been replaced with <redacted> for privacy. As you can see, the configuration is missing several key elements compared to a working example. Using a diff tool will be beneficial in comparing the differences between them.

      <?xml version="1.0" encoding="UTF-8"?><flow-definition>
          <actions/>
          <description/>
          <keepDependencies>false</keepDependencies>
          <properties>
              <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty plugin="workflow-job@1520.v56d65e3b_4566">
                  <triggers>
                      <com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl plugin="atlassian-bitbucket-server-integration@4.1.4">
                          <spec/>
                          <pullRequestTrigger>true</pullRequestTrigger>
                          <refTrigger>false</refTrigger>
                          <version>1</version>
                      </com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl>
                  </triggers>
              </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
          </properties>
          <triggers/>
          <displayName>pr-trigger-test</displayName>
          <definition plugin="workflow-cps@4106.v7a_8a_8176d450" class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition">
              <scm plugin="atlassian-bitbucket-server-integration@4.1.4" class="com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCM">
                  <branches>
                      <hudson.plugins.git.BranchSpec plugin="git@5.7.0">
                          <name>aidaleuc/smoketests</name>
                      </hudson.plugins.git.BranchSpec>
                  </branches>
                  <extensions/>
                  <id>pr-trigger-test</id>
                  <repositories>
                      <com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMRepository>
                          <credentialsId>bitbucket-service-account</credentialsId>
                          <mirrorName/>
                          <projectKey>redacted</projectKey>
                          <projectName>redacted</projectName>
                          <repositoryName>jenkins-tests</repositoryName>
                          <repositorySlug>jenkins-tests</repositorySlug>
                          <serverId>7b20f3c7-9e65-4724-8490-4a303176e25b</serverId>
                      </com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMRepository>
                  </repositories>
                  <isWebhookRegistered>false</isWebhookRegistered>
              </scm>
              <scriptPath>Jenkinsfile-hook-tests</scriptPath>
              <lightweight>false</lightweight>
          </definition>
      </flow-definition>

       

      Working config.xml: Once again I have replaced some information with <redacted>

      <?xml version='1.1' encoding='UTF-8'?>
      <flow-definition plugin="workflow-job@1520.v56d65e3b_4566">
        <actions>
          <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction plugin="pipeline-model-definition@2.2255.v56a_15e805f12"/>
          <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction plugin="pipeline-model-definition@2.2255.v56a_15e805f12">
            <jobProperties/>
            <triggers/>
            <parameters/>
            <options/>
          </org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
        </actions>
        <description></description>
        <displayName>pr-trigger-test</displayName>
        <keepDependencies>false</keepDependencies>
        <properties>
          <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
            <triggers>
              <com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl plugin="atlassian-bitbucket-server-integration@4.1.4">
                <spec></spec>
                <pullRequestTrigger>true</pullRequestTrigger>
                <refTrigger>false</refTrigger>
                <version>1</version>
              </com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl>
            </triggers>
          </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
        </properties>
        <definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@4106.v7a_8a_8176d450">
          <scm class="com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCM" plugin="atlassian-bitbucket-server-integration@4.1.4">
            <gitSCM plugin="git@5.7.0">
              <configVersion>2</configVersion>
              <userRemoteConfigs class="singleton-list">
                <hudson.plugins.git.UserRemoteConfig>
                  <name>jenkins-tests</name>
                  <url>redacted</url>
                  <credentialsId>bitbucket-service-account</credentialsId>
                </hudson.plugins.git.UserRemoteConfig>
              </userRemoteConfigs>
              <branches>
                <hudson.plugins.git.BranchSpec>
                  <name>aidaleuc/smoketests</name>
                </hudson.plugins.git.BranchSpec>
              </branches>
              <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
              <browser class="hudson.plugins.git.browser.BitbucketServer">
                <url>redacted</url>
              </browser>
              <submoduleCfg class="empty-list"/>
              <extensions/>
            </gitSCM>
            <branches reference="../gitSCM/branches"/>
            <extensions/>
            <id>pr-trigger-test</id>
            <repositories>
              <com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMRepository>
                <credentialsId>bitbucket-service-account</credentialsId>
                <mirrorName></mirrorName>
                <projectKey>redacted</projectKey>
                <projectName>redacted</projectName>
                <repositoryName>jenkins-tests</repositoryName>
                <repositorySlug>jenkins-tests</repositorySlug>
                <serverId>7b20f3c7-9e65-4724-8490-4a303176e25b</serverId>
              </com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMRepository>
            </repositories>
            <isWebhookRegistered>false</isWebhookRegistered>
          </scm>
          <scriptPath>Jenkinsfile-hook-tests</scriptPath>
          <lightweight>false</lightweight>
        </definition>
        <triggers/>
        <disabled>false</disabled>
      </flow-definition>

       

      Job DSL code:

      // Copyright © 2024 Schweitzer Engineering Laboratories, Inc.
      // SEL Confidential// Trigger combinations for Bitbucket Server integration
      def jobMap = [
          [
              name: "pr-trigger-test",
              pullRequestTrigger: true,
              refTrigger: false
          ],
          [
              name: "push-trigger-test",
              pullRequestTrigger: false,
              refTrigger: true
          ],
          [
              name: "multi-trigger-test",
              pullRequestTrigger: true,
              refTrigger: true
          ]
      ]// Creates a job with the specified trigger combination
      jobMap.each { job ->
          pipelineJob("Jenkins Smoketests/${job.name}") {
              displayName(job.name)
              definition{
                  cpsScmFlowDefinition{
                      scm{
                          BbS {
                              id(job.name)
                              branches {
                                  branchSpec {
                                      name("aidaleuc/smoketests")
                                  }
                              }
                              projectName(redacted)
                              repositoryName('jenkins-tests')
                              credentialsId('bitbucket-service-account')
                              mirrorName(null)
                              gitTool(null)
                              sshCredentialsId(null)
                              serverId('7b20f3c7-9e65-4724-8490-4a303176e25b')
                          }
                      }
                      scriptPath("Jenkinsfile-hook-tests")
                  }
              }
              properties{
                  pipelineTriggers{
                      triggers{
                          BitbucketWebhookTriggerImpl {
                              // This triggers a build after a pull request is opened, or the source branch of a pull request is updated.
                              pullRequestTrigger(job.pullRequestTrigger)
                              // This triggers a build in Bitbucket after every push to the configured repository.
                              refTrigger(job.refTrigger)
                          }
                      }
                  }
              }
              
          }
      } 

       

       

      This stack trace appears to be relevant. 

      2025-05-05 20:01:04.040+0000 [id=83]	SEVERE	o.j.p.w.j.p.PipelineTriggersJobProperty#startTriggers: Can't start trigger.5/5/2025 2:01:04 PM com.atlassian.bitbucket.jenkins.internal.client.exception.NotFoundException: - response: 4045/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.handleError(HttpRequestExecutorImpl.java:140)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.makeRequest(HttpRequestExecutorImpl.java:95)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.performRequest(HttpRequestExecutorImpl.java:160)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.executeRequest(HttpRequestExecutorImpl.java:81)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.http.HttpRequestExecutorImpl.executeGet(HttpRequestExecutorImpl.java:52)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.client.BitbucketRequestExecutor.makeGetRequest(BitbucketRequestExecutor.java:185)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.client.BitbucketRequestExecutor.makeGetRequest(BitbucketRequestExecutor.java:89)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.client.BitbucketWebhookClientImpl.getWebhooks(BitbucketWebhookClientImpl.java:59)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.register.BitbucketWebhookHandler.process(BitbucketWebhookHandler.java:139)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.register.BitbucketWebhookHandler.register(BitbucketWebhookHandler.java:53)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.RetryingWebhookHandler.registerUsingCredentials(RetryingWebhookHandler.java:96)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.RetryingWebhookHandler.registerUsingCredentialsQuietly(RetryingWebhookHandler.java:104)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.RetryingWebhookHandler.lambda$registerWithRetry$0(RetryingWebhookHandler.java:119)5/5/2025 2:01:04 PM 	at java.base/java.util.Optional.map(Unknown Source)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.RetryingWebhookHandler.registerWithRetry(RetryingWebhookHandler.java:118)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.RetryingWebhookHandler.register(RetryingWebhookHandler.java:78)5/5/2025 2:01:04 PM Caused: com.atlassian.bitbucket.jenkins.internal.trigger.register.WebhookRegistrationFailed: Failed to register webhook in bitbucket server with url https://bitbucket.metro.ad.selinc.com5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.RetryingWebhookHandler.register(RetryingWebhookHandler.java:82)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl$BitbucketWebhookTriggerDescriptor.registerWebhook(BitbucketWebhookTriggerImpl.java:296)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl$BitbucketWebhookTriggerDescriptor.lambda$addTrigger$1(BitbucketWebhookTriggerImpl.java:265)5/5/2025 2:01:04 PM 	at java.base/java.util.ArrayList.forEach(Unknown Source)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl$BitbucketWebhookTriggerDescriptor.addTrigger(BitbucketWebhookTriggerImpl.java:265)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl.lambda$start$0(BitbucketWebhookTriggerImpl.java:116)5/5/2025 2:01:04 PM 	at java.base/java.util.Optional.ifPresent(Unknown Source)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl.start(BitbucketWebhookTriggerImpl.java:114)5/5/2025 2:01:04 PM 	at PluginClassLoader for atlassian-bitbucket-server-integration//com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookTriggerImpl.start(BitbucketWebhookTriggerImpl.java:47)5/5/2025 2:01:04 PM 	at PluginClassLoader for workflow-job//org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty.startTriggers(PipelineTriggersJobProperty.java:113)5/5/2025 2:01:04 PM 	at PluginClassLoader for workflow-job//org.jenkinsci.plugins.workflow.job.WorkflowJob.onLoad(WorkflowJob.java:151)5/5/2025 2:01:04 PM 	at PluginClassLoader for cloudbees-folder//com.cloudbees.hudson.plugins.folder.AbstractFolder.loadChildren(AbstractFolder.java:396)5/5/2025 2:01:04 PM 	at PluginClassLoader for cloudbees-folder//com.cloudbees.hudson.plugins.folder.AbstractFolder.onLoad(AbstractFolder.java:484)5/5/2025 2:01:04 PM 	at PluginClassLoader for cloudbees-folder//com.cloudbees.hudson.plugins.folder.Folder.onLoad(Folder.java:117)5/5/2025 2:01:04 PM 	at hudson.model.Items.load(Items.java:376)5/5/2025 2:01:04 PM 	at jenkins.model.Jenkins$14.run(Jenkins.java:3498)5/5/2025 2:01:04 PM 	at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:175)5/5/2025 2:01:04 PM 	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:304)5/5/2025 2:01:04 PM 	at jenkins.model.Jenkins$5.runTask(Jenkins.java:1149)5/5/2025 2:01:04 PM 	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:221)5/5/2025 2:01:04 PM 	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:120)5/5/2025 2:01:04 PM 	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)5/5/2025 2:01:04 PM 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)5/5/2025 2:01:04 PM 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)5/5/2025 2:01:04 PM 	at java.base/java.lang.Thread.run(Unknown Source) 

       

       

            Unassigned Unassigned
            aidaleuc Aidan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: