Search code examples
jenkinsmercurialjenkins-pipelinetortoisehgvcs-checkout

Jenkins will not continue pipeline after updating via Mercurial plugin


I'm trying to setup a CI process using Jenkins with the source code being held in Mercurial, so I have the Jenkins Mercurial Plugin installed.

It's a simple pipeline script just now which polls my repository every 10 minutes. Using the checkout command below and hitting Build Now on my job it successfully clones my repository and continues with the pipeline as expected. It also successfully sets up polling and I can see from the polling log that it is checking the repository for changes every 10 minutes.

checkout changelog: true, poll: true, scm: [$class: 'MercurialSCM', credentialsId: 'xxx', installation: 'TortoiseHg', source: 'C:\\Path\\to\\repo']

However, when I push to my repository, Jenkins on next running the job spots these changes, pulls them down but then reports back 'No changes' and so the job stops. I expected that at this point the job would continue because there are changes. Of course if there were no changes I would expect it to stop the job at this point.

The Mercurial Polling Log shows the changes have been pulled but hg update has not been run. This is confirmed by looking at the Jenkins-created-repo in the Tortoise Workbench. However, even putting a hook in Mercurial configuration in Jenkins such that it does update after pulling does not fix the issue. Jenkins still reports 'No changes' after the checkout step.

So after the initial build, which works fine, Jenkins never runs the job all the way through again. It always bails out after the checkout step because despite pulling down any changes it reports there are none.

I have checked the permissions and everything seems fine, the fact that it completely runs on demand and can subsequently pull also suggests there is nothing wrong with the pipeline or elsewhere.

Any suggestions as to how to get the job to continue after the checkout stage would be much appreciated.

Below is an example pipeline script:

pipeline {
    agent any

    triggers {
        pollSCM '*/10 * * * *'
    }

    stages {
        stage('Checkout') {
            steps {
                checkout changelog: true, poll: true, scm: [$class: 'MercurialSCM', credentialsId: 'xxx', installation: 'TortoiseHg', source: 'C:\\Path\\to\\repo']
            }
        }
        stage('Build') {
            steps {
                echo Continuing with build...
            }
        }
    }

UPDATE I have noticed that if I manually build after the poll has pulled down but not updated the local repository the job then updates the repository and the build continues as normal.


Solution

  • It looks like you have omitted to specify a branch in your scm checkout. Are you using the default branch in HG?

    This Jenlins issue and the source code show that if you are not using the deault branch, you'll likely not see your changes pulled down even if the references are there.

    If you are trying to build a non default branch give this a try

    checkout changelog: true, poll: true, scm: [$class: 'MercurialSCM',  branches: [[name: '*/yourbranch']],  credentialsId: 'xxx', installation: 'TortoiseHg', source: 'C:\\Path\\to\\repo']