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

First time build does not show changelog

    Details

    • Similar Issues:

      Description

      Suppose, we have master branch. Then we checkout to a new branch, lets name it branch1:

      git checkout -b branch1
      

      Then we do some commits:

      echo "a" > a.txt && git add a.txt && git commit -m 'Added file: a.txt'
      echo "b" > b.txt && git add b.txt && git commit -m 'Added file: b.txt'
      

      Then we push our branch to Git repository:

      git push origin branch1
      

      In Jenkins, Git polling reports:

      ...
      Seen branch in repository origin/branch1
      Seen XXX remote branches
       > /usr/bin/git log --full-history --no-abbrev --format=raw -M -m --raw 0a6eb107fea5bb6371c450db1b5f6e100e0fba28..d8c5018ca184fb75e46386de2f16e552906fe106 # timeout=10
      Done. Took 3.5 sec
      Changes found
      

      but Changes section shows nothing, it means, that no changes were made. Nevertheless, build was triggered.

      The problem is deeper, suppose our build runs unit tests, and they failed. In that case, no emails will be send to committers, because of no changes. We have caught this case and got a problems
      I think, it's a bug, because 2 new commits were created and Jenkins should show it in Changes section.

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment - - edited

          Oleg Stepura Pull request 637 includes a proposal to provide a changelog for the first build of a branch. It is currently in the "Later" milestone because it is not receiving my focused evaluation right now. After git plugin 4.0 has stabilized and released, I'll evaluate the pull requests in the "Later" milestone to decide which should be reopened and be reviewed.

          I'd love to have your help evaluating the changes that are proposed in that pull request. You'd need to build a local copy of the plugin based on that pull request, use it in your environment, and report the results to the pull request.

          If you're not comfortable building the pull request, I could temporarily reopen the request, have the CI servers build it, then point you to the built artifact so that you could test it.

          See JENKINS-14138 and that pull request for more details

          Show
          markewaite Mark Waite added a comment - - edited Oleg Stepura Pull request 637 includes a proposal to provide a changelog for the first build of a branch. It is currently in the "Later" milestone because it is not receiving my focused evaluation right now. After git plugin 4.0 has stabilized and released, I'll evaluate the pull requests in the "Later" milestone to decide which should be reopened and be reviewed. I'd love to have your help evaluating the changes that are proposed in that pull request. You'd need to build a local copy of the plugin based on that pull request, use it in your environment, and report the results to the pull request. If you're not comfortable building the pull request, I could temporarily reopen the request, have the CI servers build it, then point you to the built artifact so that you could test it. See JENKINS-14138 and that pull request for more details
          Hide
          olegstepura Oleg Stepura added a comment -

          Hi!

          Thanks for quick reply and sorry I did not react as fast. I discussed internally if this is acceptable to do what you suggested and it was not, but another option to workaround the limitations here was found: JENKINS-54285

          I tried using commands from that ticket, it works if we use big enough shallow clone depth (I set it to 100).

          the only issue I faced was being unable to use sh in a function. It looks buggy. Seems like I cannot simply define a function like this:

           

          def getLastCommitHash() {
            return sh(
              returnStdout: true,
              script: "git show -s --no-abbrev-commit --pretty=format:%P%n%H%n HEAD"
            ).trim().split("\n").last().trim()
          }

           

          and the use it: 

          def otherFunction() {
            def lastCommit = getLastCommitHash()
            // do something else with it expecting lastCommit has one-line string
            return [a, b, c]
          }

          In the example above otherFunction() will return exact unprocessed output of sh command from getLastCommitHash() function. This is weird.

          I was able to workaround this creating simple functions which only run sh commands and do no post-processing (just return sh output) and other functions that only work with strings and not do anything with sh. Then all those functions are used together inside our main node {} context.

          def getHeads() {
            return sh(
              returnStdout: true,
              script: "git show -s --no-abbrev-commit --pretty=format:%P%n%H%n HEAD"
            )
          }
          
          def getLastCommitHash(headsOutput) {
            return headsOutput.trim().split("\n").last().trim()
          }

           then use this in Jenkinsfile:

          node("xxx") {
            def headsOutput = getHeads()
            def lastCommitHash = getLastCommitHash(headsOutput)
            // ...
          }

           

          Show
          olegstepura Oleg Stepura added a comment - Hi! Thanks for quick reply and sorry I did not react as fast. I discussed internally if this is acceptable to do what you suggested and it was not, but another option to workaround the limitations here was found:  JENKINS-54285 I tried using commands from that ticket, it works if we use big enough shallow clone depth (I set it to 100). the only issue I faced was being unable to use sh in a function. It looks buggy. Seems like I cannot simply define a function like this:   def getLastCommitHash() { return sh( returnStdout: true , script: "git show -s --no-abbrev-commit --pretty=format:%P%n%H%n HEAD" ).trim().split( "\n" ).last().trim() }   and the use it:  def otherFunction() { def lastCommit = getLastCommitHash() // do something else with it expecting lastCommit has one-line string return [a, b, c] } In the example above  otherFunction() will return exact unprocessed output of sh command from  getLastCommitHash() function. This is weird. I was able to workaround this creating simple functions which only run sh commands and do no post-processing (just return sh output) and other functions that only work with strings and not do anything with sh . Then all those functions are used together inside our main node { } context. def getHeads() { return sh( returnStdout: true , script: "git show -s --no-abbrev-commit --pretty=format:%P%n%H%n HEAD" ) } def getLastCommitHash(headsOutput) { return headsOutput.trim().split( "\n" ).last().trim() }  then use this in Jenkinsfile: node( "xxx" ) { def headsOutput = getHeads() def lastCommitHash = getLastCommitHash(headsOutput) // ... }  
          Hide
          tamerlaha ipleten added a comment -

          Is that really resolved?

          The problem is really serious  we can't use 'changeset' in when condition with branches at all.

          Show
          tamerlaha ipleten added a comment - Is that really resolved? The problem is really serious  we can't use 'changeset' in when condition with branches at all.
          Hide
          markewaite Mark Waite added a comment - - edited

          It is resolved as "Won't Fix". Refer to the earlier discussions for more details.

          There is this pull request that attempts to apply heuristics to decide which change should be used as the basis for a changeset. You're welcome to propose further changes to it to resolve the issues that are discussed in it.

          Show
          markewaite Mark Waite added a comment - - edited It is resolved as "Won't Fix". Refer to the earlier discussions for more details. There is this pull request that attempts to apply heuristics to decide which change should be used as the basis for a changeset. You're welcome to propose further changes to it to resolve the issues that are discussed in it.
          Hide
          azelezni Alex Zeleznikov added a comment -

          I was able to get the changeset using the following:

          checkout scm: [
              $class: 'GitSCM',
              branches: [[name: env.BRANCH_NAME]],
              extensions: [
                  [
                      $class: 'ChangelogToBranch',
                      options: [
                          compareRemote: 'origin',
                          compareTarget: 'master'
                      ]
                  ]
              ],
              userRemoteConfigs: [
                  [
                      url: scm.getUserRemoteConfigs()[0].getUrl(),
                      refspec: scm.getUserRemoteConfigs()[0].getRefspec(),
                      credentialsId: 'github-privatekey'
                  ]
              ]
          ]
          

          With the above I can get a changeset from the first build.

           

          Show
          azelezni Alex Zeleznikov added a comment - I was able to get the changeset using the following: checkout scm: [ $class: 'GitSCM' , branches: [[name: env.BRANCH_NAME]], extensions: [ [ $class: 'ChangelogToBranch' , options: [ compareRemote: 'origin' , compareTarget: 'master' ] ] ], userRemoteConfigs: [ [ url: scm.getUserRemoteConfigs()[0].getUrl(), refspec: scm.getUserRemoteConfigs()[0].getRefspec(), credentialsId: 'github-privatekey' ] ] ] With the above I can get a changeset from the first build.  

            People

            • Assignee:
              ndeloof Nicolas De Loof
              Reporter:
              maxusachev Max Usachev
            • Votes:
              0 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: