[JIRA] (JENKINS-56341) GIT_COMMIT can point to a no repo commit SHA

3 views
Skip to first unread message

kuisathaverat@gmail.com (JIRA)

unread,
Mar 1, 2019, 6:51:02 AM3/1/19
to jenkinsc...@googlegroups.com
Ivan Fernandez Calvo updated an issue
 
Jenkins / Improvement JENKINS-56341
GIT_COMMIT can point to a no repo commit SHA
Change By: Ivan Fernandez Calvo
Summary: GIT_COMMIT can point to a not no repo commit SHA
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

carpnick@gmail.com (JIRA)

unread,
Jun 19, 2019, 10:15:02 AM6/19/19
to jenkinsc...@googlegroups.com
Nick Carpenter commented on Improvement JENKINS-56341
 
Re: GIT_COMMIT can point to a no repo commit SHA

Wrestled this awhile myself.  Used the following function instead since I checkout to a local branch:

    private String getRealLastCommit(branch_name){
        def lastCommit=""
        
        if(steps.isUnix()){
            lastCommit = steps.sh([script: "git log -1  --pretty=format:\"%H\" origin/${branch_name}", returnStdout: true]).trim()
        }
        else{
            lastCommit = steps.bat([script: "git log -1 --format=\"%%H\" origin/${branch_name}", returnStdout: true]).split( '\n' )[2].trim()
        }
        
        steps.echo("DEBUG Last Commit ID:${lastCommit}")
        return lastCommit
    }

 

carpnick@gmail.com (JIRA)

unread,
Jun 19, 2019, 10:16:02 AM6/19/19
to jenkinsc...@googlegroups.com
Nick Carpenter edited a comment on Improvement JENKINS-56341
Wrestled this awhile myself.  Used the following function instead since I checkout to a local branch:
{code:java}

    private String getRealLastCommit(branch_name){
        def lastCommit=""
        
        if(steps.isUnix()){
            lastCommit = steps.sh([script: "git log -1  --pretty=format:\"%H\" origin/${branch_name}", returnStdout: true]).trim()
        }
        else{
            lastCommit = steps.bat([script: "git log -1 -- pretty= format=\"%%H\" origin/${branch_name}", returnStdout: true]).split( '\n' )[2].trim()

        }
        
        steps.echo("DEBUG Last Commit ID:${lastCommit}")
        return lastCommit
    }
{code}
 
Reply all
Reply to author
Forward
0 new messages