jenkinsci/git-changelog-plugin

Commits returned from pipeline step are different from git log and freestyle post build action

Closed this issue · 10 comments

  • Plugin version used = Version: 3.0
  • Jenkins version used = 2.260
  • Your configuration:
    • Template and any other relevant details =
      Running as a pipeline step, we call a function that performs the gitChangelog step.
def get_changelog_string(gitUrl,from,to,template = changeLogTemplate, throwException = true){
    try{
        git gitUrl
        sh "git log --pretty=oneline '$from'...'$to'"

        def changeLogString = gitChangelog returnType: 'STRING',
                from: [type: 'REF', value: from],
                to: [type: 'REF', value: to],
                template: changeLogTemplate,
                ignoreCommitsWithoutIssue : false,
                jira: [issuePattern: '([A-Z0-9])+-([0-9])+\\b', password: '***"', server: ''****', username: '****']

        return changeLogString
    }
    catch (Exception ex){
        def fullErrorMessage = "Unable to get changelog of '${gitUrl}: ${ex}"
        if(throwException){
            error fullErrorMessage
        }
        println fullErrorMessage
        return "<h1>Unable to get changelog of '${gitUrl}', check console output for more detailes</h1>"
    }

}
  • Expected result and actual result.
    We input tags to the git log and no commits are returned, and we get the same result (no commits) with these tags when we call the plugin with the post build actions on a freestyle job
    git log --pretty=oneline craton2-platform-sdk-5.13.1-beta2...craton2-platform-sdk-5.13.1-rc1 returns nothing
    same on the freestyle job
    image

but on the report of the pipeline created we get :
image

  • Any information from the logs:
    • Jenkins log:
Replayed #197
Started by user Dan Assael
Rebuilds build #202
Checking out git ssh://git@bitb.il.auto-talks.com/auto/swqa-jenkins-pipelines.git into /var/jenkins_home/workspace/Create_release_notes@script to read pipelines/create_release_notes.groovy
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url ssh://git@bitb.il.auto-talks.com/auto/swqa-jenkins-pipelines.git # timeout=10
Fetching upstream changes from ssh://git@bitb.il.auto-talks.com/auto/swqa-jenkins-pipelines.git
 > git --version # timeout=10
 > git --version # 'git version 2.11.0'
 > git fetch --tags --progress -- ssh://git@bitb.il.auto-talks.com/auto/swqa-jenkins-pipelines.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse origin/master^{commit} # timeout=10
Checking out Revision 21bda9e7b993d3f4170df34a22c1a52a3d7be1b8 (origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 21bda9e7b993d3f4170df34a22c1a52a3d7be1b8 # timeout=10
Commit message: "tags specifically"
 > git rev-list --no-walk ce01baedea57a1a3888b86b1e981965b34958bcb # timeout=10
[Checks API] No suitable checks publisher found.
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] properties
[Pipeline] ansiColor
[Pipeline] {

[Pipeline] node
Running on ub04 in /local/jenkins/workspace/Create_release_notes
[Pipeline] {
[Pipeline] cleanWs
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] done
[Pipeline] stage
[Pipeline] { (get changes from device)
[Pipeline] git
The recommended git tool is: NONE
No credentials specified
Cloning the remote Git repository
Cloning repository ssh://git@bitb.il.auto-talks.com/sdk/device.git
 > git init /local/jenkins/workspace/Create_release_notes # timeout=10
Fetching upstream changes from ssh://git@bitb.il.auto-talks.com/sdk/device.git
 > git --version # timeout=10
 > git --version # 'git version 2.7.4'
 > git fetch --tags --progress ssh://git@bitb.il.auto-talks.com/sdk/device.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
Checking out Revision f0912699e5384d2362b35af3920171c4c010ff06 (refs/remotes/origin/master)
Commit message: "Fixed empty_tx processing in SECTON SPI master mode (PLAT-1174)"
 > git config remote.origin.url ssh://git@bitb.il.auto-talks.com/sdk/device.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git config core.sparsecheckout # timeout=10
 > git checkout -f f0912699e5384d2362b35af3920171c4c010ff06 # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git checkout -b master f0912699e5384d2362b35af3920171c4c010ff06 # timeout=10
 > git rev-list --no-walk f0912699e5384d2362b35af3920171c4c010ff06 # timeout=10
[Checks API] No suitable checks publisher found.
[Pipeline] sh
+ git log --pretty=oneline refs/tags/craton2-platform-sdk-5.13.1-beta2...refs/tags/craton2-platform-sdk-5.13.1-rc1
[Pipeline] gitChangelog
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (get changes from host)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (get changes from cv2x)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (get changes from DSRC DSP)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (get changes from CV2X DSP)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (get changes from platform)
[Pipeline] git
The recommended git tool is: NONE
No credentials specified
Fetching changes from the remote Git repository
 > git rev-parse --is-inside-work-tree # timeout=10
 > git config remote.origin.url ssh://git@bitb.il.auto-talks.com/plat/qnx.git # timeout=10
Fetching upstream changes from ssh://git@bitb.il.auto-talks.com/plat/qnx.git
 > git --version # timeout=10
 > git --version # 'git version 2.7.4'
 > git fetch --tags --progress ssh://git@bitb.il.auto-talks.com/plat/qnx.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision 07558168cc68ea5b52d9a1bec597df1f95f88538 (refs/remotes/origin/master)
Commit message: "Automatic merge from release/qnx-3.0.0 -> master"
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 07558168cc68ea5b52d9a1bec597df1f95f88538 # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master 07558168cc68ea5b52d9a1bec597df1f95f88538 # timeout=10
 > git rev-list --no-walk 07558168cc68ea5b52d9a1bec597df1f95f88538 # timeout=10
[Checks API] No suitable checks publisher found.
[Pipeline] sh
+ git log --pretty=oneline qnx-dist-atlk-3.0.0-beta2...qnx-dist-atlk-3.0.0-rc1
3bbb041a916bd5984232c85c725cbb6f5bd871d4 add support for telent using PAM modole (bugfix/PLAT-902)
1e2de288dfca86047fd1d07db8a35a7d1d58c0bc Build only threadx when making distribution (PLAT-1175)
6016128466f52b0257de874c5df76bfabc71963d Ethernet: Worked around big files SCP fail (PLAT-350)
809e6b550b99a0e2d91e32ef53f6d2a81c68292d Prevent delivery of threadx (PLAT-1175)
27be29ae5f33fcdacf77a5267c02786c4664a64d DHCP client: Fixed initialization (PLAT-1152)
d6fb9105423b88af724e3e06ccfe014c783f2d1a Update m3-loader (PLAT-1169)
[Pipeline] gitChangelog
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (publish_html)
[Pipeline] writeFile
[Pipeline] publishHTML
[htmlpublisher] Archiving HTML reports...
[htmlpublisher] Archiving at BUILD level /local/jenkins/workspace/Create_release_notes/reports to /var/jenkins_home/jobs/Create_release_notes/builds/203/htmlreports/Reports
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }

[Pipeline] // ansiColor
[Pipeline] End of Pipeline
[Checks API] No suitable checks publisher found.
Notified JIRA that a build has completed.
Finished: SUCCESS

Use 2 dots: '$from'..'$to'.

The plugin finds all commits in "to" that are not in "from". Or, that is the intention.

[Pipeline] sh
+ git log --pretty=oneline craton2-platform-sdk-5.13.1-beta2..craton2-platform-sdk-5.13.1-rc1
[Pipeline] gitChangelog

Using .. yields no commits as well.

Both beta2 and rc1 are on the same commit in this specific case, does it still behave that way?
How come the the same tags input into the plugin as a post action in a configuration job doesnt return any commits?

How did you configure that post build action?

I pass parameters for the tags I want to get the changelog for, everything else is default.
image

*not showing the jira connection data

Below this screenshot you have options on how you want to present the result. What did you pick?

I copied over the template we used in the pipeline job
image

I think it might be this:

.withIgnoreCommitsWithMessage(nullToEmpty(ignoreCommitsIfMessageMatches)) //

When using the pipeline step, ignoreCommitsIfMessageMatches will be empty and not null.

When using the post build action, it will not be null and not be empty but it will be the string you have in your GUI.

This means no filter will be used in the pipeline step:
https://github.com/tomasbjerre/git-changelog-lib/blob/73f54645bd6f6fa17543337ac4b66451f37f03c6/src/main/java/se/bjurr/gitchangelog/internal/settings/Settings.java#L272

And a quick fix should be to give the step ignoreCommitsIfMessageMatches like:

        def changeLogString = gitChangelog returnType: 'STRING',
                from: [type: 'REF', value: from],
                to: [type: 'REF', value: to],
                template: changeLogTemplate,
                ignoreCommitsWithoutIssue : false,
                ignoreCommitsIfMessageMatches: '^Merge.*',
                jira: [issuePattern: '([A-Z0-9])+-([0-9])+\\b', password: '***"', server: ''****', username: '****']

MaorT commented

Hi,
We tried to add the ignoreCommitsIfMessageMatches: '^Merge.*' , and then we didn't got the commit with 'Merge' in it's message but got the other commits even they are not a 'change' (The from-to tags are on the same commit )

You need to provide the same logging again. As you previously did when not having this filter.

We decided to check if the Tags given both point to the same commit and return no changes if it does, before calling the plugin.
As we worked around it I am closing this issue.

If you want to try and reproduce this behavior :
Push a commit (not a merge)
Add tag1 to the commit
Add tag2 to the commit
Add tag3 to the commit
Run the pipeline step from tag1 to tag3.