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

Mercurial triggers broken by duplicate checkout in Multibranch pipeline

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Labels:
      None
    • Environment:
      Jenkins 2.99
      Pipeline: Multibranch 2.16
      Bitbucket Plugin 1.1.8
      Mercurial Plugin 2.2
    • Similar Issues:

      Description

      In my multibranch job I see mercurial build data twice as discussed elsewhere. However this breaks the bitbucketPush() and pollSCM trigger, at least on my single instance, build on master setup. The below output from the bitbucket hook log shows the second checkout can't find any new changes and so does not trigger the build.

      [EE594BC60F600AD3DD68DECB293CF28AC8C8D9FF-testrepo] $ hg pull
      pulling from https://bitbucket.org/aphtech/testrepo
      searching for changes
      adding changesets
      adding manifests
      adding file changes
      added 1 changesets with 1 changes to 1 files
      (run 'hg update' to get a working copy)
      Master cache lock released.
      [EE594BC60F600AD3DD68DECB293CF28AC8C8D9FF-testrepo] $ hg log --rev f9086558ba7491029c1dc288c81536bb666b1fd8 --template {node}
      [EE594BC60F600AD3DD68DECB293CF28AC8C8D9FF-testrepo] $ hg log --rev f9086558ba7491029c1dc288c81536bb666b1fd8 --template {rev}
      [EE594BC60F600AD3DD68DECB293CF28AC8C8D9FF-testrepo] $ hg id --branch --rev f9086558ba7491029c1dc288c81536bb666b1fd8
      Acquired master cache lock.
      [EE594BC60F600AD3DD68DECB293CF28AC8C8D9FF-testrepo] $ hg pull
      pulling from https://bitbucket.org/aphtech/testrepo
      searching for changes
      no changes found
      Master cache lock released.
      [EE594BC60F600AD3DD68DECB293CF28AC8C8D9FF-testrepo] $ hg log --rev f9086558ba7491029c1dc288c81536bb666b1fd8 --template {node}
      [EE594BC60F600AD3DD68DECB293CF28AC8C8D9FF-testrepo] $ hg log --rev f9086558ba7491029c1dc288c81536bb666b1fd8 --template {rev}
      [EE594BC60F600AD3DD68DECB293CF28AC8C8D9FF-testrepo] $ hg id --branch --rev f9086558ba7491029c1dc288c81536bb666b1fd8
      Done. Took 2.2 sec
      No changes
      

      My base Jenkinsfile is pretty basic

      pipeline {
          agent any
          
          triggers {
      		bitbucketPush()
      	}
      
      	stages {
      		stage("Build Data") {
      			steps {
      				sh 'echo yay'
      			}
      		}
          }
      }
      

      I've tried with `checkout scm`, `skipDefaultCheckout()`, and inside a docker agent instead of master but cannot get rid of the second repo

      Steps to reproduce

      1. Make a multibranch job from a mercurial repo on bitbucket
      2. Let it do the initial build, mercurial build data should be duplicated
      3. # Add bitbucket-hook/ url to bitbucket webhooks
      4. Try to trigger via push or pollSCM

      This bug makes multibranch almost unusable

        Attachments

          Activity

          Hide
          thelq Leon Blakey added a comment -

          Reproduced on a vanilla Jenkins 2.99 installation, Pipeline Multibranch 2.16, Mercurial 2.2, Bitbucket 1.1.8

          1. Run weekly docker image
          2. Install Pipeline: Multibranch, mercurial, and bitbucket plugins
          3. Create mutlibranch job with mercurial source
          4. Let it do the initial build
          5. Default branch has 2 bitbucket instances
          6. Push to mercurial repo
          7. Get above output in Bitbucket Hook log, no build is ran
          Show
          thelq Leon Blakey added a comment - Reproduced on a vanilla Jenkins 2.99 installation, Pipeline Multibranch 2.16, Mercurial 2.2, Bitbucket 1.1.8 Run weekly docker image Install Pipeline: Multibranch, mercurial, and bitbucket plugins Create mutlibranch job with mercurial source Let it do the initial build Default branch has 2 bitbucket instances Push to mercurial repo Get above output in Bitbucket Hook log, no build is ran
          Hide
          thelq Leon Blakey added a comment -

          If anyone still wants webhook triggers, you can host this script and point Bitbucket to it

          jenkinsWebHook.php

           

           

          Show
          thelq Leon Blakey added a comment - If anyone still wants webhook triggers, you can host this script and point Bitbucket to it jenkinsWebHook.php    
          Hide
          bren Brendon Colby added a comment -

          This is happening to me too. I see two hg pulls and the changelog has duplicate entries. The second pull results in no changes and the job never runs. I've tried a bunch of different stuff but I can't get this to work.

          Show
          bren Brendon Colby added a comment - This is happening to me too. I see two hg pulls and the changelog has duplicate entries. The second pull results in no changes and the job never runs. I've tried a bunch of different stuff but I can't get this to work.
          Hide
          bren Brendon Colby added a comment -

          OK - so what I did to get around this is I created a regular pipeline and repo push now triggers the build. I still see duplicates in the changelog but that's not a deal breaker. We don't use branches in our Mercurial repos so this works for us.

          Show
          bren Brendon Colby added a comment - OK - so what I did to get around this is I created a regular pipeline and repo push now triggers the build. I still see duplicates in the changelog but that's not a deal breaker. We don't use branches in our Mercurial repos so this works for us.
          Hide
          bren Brendon Colby added a comment - - edited

          I decided to troubleshoot this more. I can't for the life of me get a multibranch pipeline to trigger. In the jenkins.log, it says:

           

          INFO: Triggering BitBucket job default
          

           

          I see in the Bitbucket Hook Log that it runs "/usr/bin/hg pull" and that the new changesets DO get pulled in, but for some reason it always says "No changes" and doesn't trigger the pipeline to run no matter what I do. So for whatever reason, multibranch pipelines with Bitbucket and Mercurial seem to be broken.

          We don't use branches in these repos so I created a regular pipeline project (not sure why I didn't do this in the first place). I CAN get these to run on a push, but it creates duplicate changelog entries. In the Bitbucket Hook Log, I see a series of Mercurial commands run twice. The pipeline is called "test-staging" so I see "hg pull" etc. run for "test-staging@script" and then again for "test-staging". I assume the first one is to pull in the Jenkinsfile and the second is the default SCM checkout.

          If I add this to the Jenkinsfile:

          options {
            skipDefaultCheckout()
          }
          

          Then I see exactly one changelog entry per commit. Of course, the local repo is never updated, so I added a "Checkout" stage that runs "hg update" (because the changesets were already pulled down by the pipeline itself). This seems to work well for us.

          Of course, this won't work on the initial pipeline setup because the repo has to be cloned first, but in that case all you need to do is leave out skipDefaultCheckout() on the first run then add it back in after that.

          Show
          bren Brendon Colby added a comment - - edited I decided to troubleshoot this more. I can't for the life of me get a multibranch pipeline to trigger. In the jenkins.log, it says:   INFO: Triggering BitBucket job default   I see in the Bitbucket Hook Log that it runs "/usr/bin/hg pull" and that the new changesets DO get pulled in, but for some reason it always says "No changes" and doesn't trigger the pipeline to run no matter what I do. So for whatever reason, multibranch pipelines with Bitbucket and Mercurial seem to be broken. We don't use branches in these repos so I created a regular pipeline project (not sure why I didn't do this in the first place). I CAN get these to run on a push, but it creates duplicate changelog entries. In the Bitbucket Hook Log, I see a series of Mercurial commands run twice. The pipeline is called "test-staging" so I see "hg pull" etc. run for "test-staging@script" and then again for "test-staging". I assume the first one is to pull in the Jenkinsfile and the second is the default SCM checkout. If I add this to the Jenkinsfile: options { skipDefaultCheckout() } Then I see exactly one changelog entry per commit. Of course, the local repo is never updated, so I added a "Checkout" stage that runs "hg update" (because the changesets were already pulled down by the pipeline itself). This seems to work well for us. Of course, this won't work on the initial pipeline setup because the repo has to be cloned first, but in that case all you need to do is leave out skipDefaultCheckout() on the first run then add it back in after that.

            People

            • Assignee:
              Unassigned
              Reporter:
              thelq Leon Blakey
            • Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: