compute changes on PRs on a multibranch pipeline

612 views
Skip to first unread message

Ivan Fernandez Calvo

unread,
Dec 10, 2018, 9:39:05 AM12/10/18
to Jenkins Users
Hi,

I am trying to show PRs related changes on Multibranch pipeline (MBP) jobs when a PR is created, I could not make it, I only see changes it the PR is modified with new commits. The "Calculate changelog against a specific branch" git behavior is not available on MBP jobs so I use a custom checkout, Is it possible? What do I wrong?

Screenshot 2018-12-10 at 15.30.06.png


Jenkins 2.155, 
Pipeline 2.2, 

Declarative pipeline 1.33, 

Pipeline: Multibranch 2.20, 
Pipeline: SCM Step 2.7, 

SCM API Plugin 2.3.0, 

Github API 1.95, 

Basic Branch Build Strategies Plugin 1.1.1, 

Branch API Plugin 2.1.1, 
GitHub Branch Source Plugin 2.4.1


regular checkout does not compute changes (I suppose that in this case is correct)

pipeline {
  agent any
  options {
    timeout(time: 1, unit: 'HOURS')
    buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
    timestamps()
    ansiColor('xterm')
    disableResume()
    durabilityHint('PERFORMANCE_OPTIMIZED')
  }
  stages {
    stage('Dummy'){
      steps {
        sh 'export'
        checkout scm
      }
    }
  }
}


using a reference repo checkout does not compute changes (I suppose that in this case is correct)

pipeline {
  agent { label 'master'}
  options {
    timeout(time: 1, unit: 'HOURS')
    buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
    timestamps()
    ansiColor('xterm')
    disableResume()
    durabilityHint('PERFORMANCE_OPTIMIZED')
  }
  stages {
    stage('Dummy'){
      steps {
        checkout([$class: 'GitSCM', 
        branches: [[name: "${env?.CHANGE_ID ? env?.GIT_COMMIT : env?.BRANCH_NAME}"]], 
        doGenerateSubmoduleConfigurations: false, 
        extensions: [[$class: 'CloneOption', 
          noTags: false, 
          reference: '/var/lib/jenkins/.git-references/apm-agent-go.git', 
          shallow: false]], 
        submoduleCfg: [], 
        userRemoteConfigs: [[credentialsId: 'UserAndToken', 
        url: "${env?.GIT_URL}"]]])
      }
    }
  }
}


using ChangelogToBranch checkout does not compute changes, here it should compute the changes with the reference branch

pipeline {
  agent any
  options {
    timeout(time: 1, unit: 'HOURS')
    buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
    timestamps()
    ansiColor('xterm')
    disableResume()
    durabilityHint('PERFORMANCE_OPTIMIZED')
  }
  stages {
    stage('Dummy'){
      steps {
        checkout([$class: 'GitSCM', 
          branches: [[name: "${env?.CHANGE_ID ? env?.GIT_COMMIT : env?.BRANCH_NAME}"]],
          doGenerateSubmoduleConfigurations: false, 
          extensions: [
            [$class: 'ChangelogToBranch', 
              options: [compareRemote: "origin", 
              compareTarget: "master"]]], 
          submoduleCfg: [], 
          userRemoteConfigs: [
            [credentialsId: 'UserAndToken', 
            url: "${env?.GIT_URL}"]]])
      }
    }
  }
}

Mark Waite

unread,
Dec 10, 2018, 9:22:24 PM12/10/18
to Jenkins Users
As far as I know, the git plugin won't compute the changelog for the first build on a branch.  It short circuit evaluates for the first build of a job.

There are some different proposals to change that, including https://github.com/jenkinsci/git-plugin/pull/637 that is attempting to apply heuristics that will decide the changelog of the first build and https://github.com/jenkinsci/git-plugin/pull/599 and https://github.com/jenkinsci/git-plugin/pull/552.  There are some other pull requests related to changelogs as well, see https://github.com/jenkinsci/git-plugin/labels/5%20-%20Changelog

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1e562716-319e-4b7e-82d6-eb355455b391%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Thanks!
Mark Waite

Mark Waite

unread,
Dec 10, 2018, 9:31:04 PM12/10/18
to Jenkins Users
I was wrong.  A Freestyle job using the "Calculate changelog against a specific branch" additional behaviour will show the changelog from a base branch to the first build of a new job on a different branch.  I'll need to investigate further to confirm that it doesn't work for Pipeline even though it works for Freestyle.

Mark Waite
--
Thanks!
Mark Waite

Mark Waite

unread,
Dec 10, 2018, 10:02:11 PM12/10/18
to Jenkins Users
I was able to compute a changelog on the first build of a multibranch Pipeline using the Jenkinsfile at https://github.com/MarkEWaite/jenkins-bugs/blob/JENKINS-54xxx/Jenkinsfile .  However, that was not from a pull request, rather it was from a build of the branch.
--
Thanks!
Mark Waite

Mark Waite

unread,
Dec 10, 2018, 10:16:57 PM12/10/18
to Jenkins Users
And, to confirm what you described, I was unable to compute a changelog on the first build of a pull request on a multibranch Pipeline using https://github.com/MarkEWaite/jenkins-bugs/blob/JENKINS-54xxx/Jenkinsfile 

That seems like an expected behavior based on the multibranch Pipeline definition menu.  It does not include a menu item to calculate a changelog against a named branch.  The options offered in the multibranch pipeline menu were intentionally limited to a subset of options that made the most sense in the context of a multibranch pipeline.  It appears that calculating a changelog against a base branch was not intended to be part of multibranch pipelines.

I'm not sure why calculating the changelog works against a base branch works for a job of a multibranch pipeline but not for a pull request of a multibranch pipeline.  I suspect "luck" or "accident" is the reason more than intended behavior.

Mark Waite


--
Thanks!
Mark Waite

kuisathaverat

unread,
Dec 11, 2018, 6:08:34 AM12/11/18
to jenkins...@googlegroups.com
thank you so much for deep dive into this ;)

You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/Ew-7R2rToDQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtE%2BT0UaTWJfFTRF_ut89vx-egbjJiOrx8HbEWP9vdAHRg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages