How to get the latest commit messages within a pus

2019-06-09 06:02发布

问题:

I have two questions 1. Try to parse for git commit messages, but the egrep execute as a separate command. The return result is always incorrect. The valid message can be "a-1"

stage('test') {
        steps {           
            script {
                def result = sh(script: "git log -1 --pretty=%B | egrep '(([a-zA-Z ]+-\\d+[, \t\n]*)+)(.*)'", returnStatus: true)

                if (result == 0) {
                    echo "continuous building..."
                } else {
                    echo "Incorrect commit message prefix. Aborting"
                    exit 1
                }
            }

        }
    }

Run result. Here it shows processor has separated the '|' into two commands and executed separately. How can I make it back into one?

[Microscope_PR-2-I4FUBH4BH2EXP7UKWZIUYPCCCB] Running shell script

+ git log -1 --pretty=%B

+ egrep '(([a-zA-Z ]+-\d+[, \t\n]*)+)(.*)'
  1. Besides, there could be multiple commits before a git push. How can I check for all the commits instead of only the last one? "git log -1", only return the last one commits, but not all before the git push. Example is

    >git commit -a -m "test1"
    >git commit -a -m "test2"
    >git commit -a -m "test3"
    >git push origin HEAD
    

Hope to use the git log or other command to obtain

    test1
    test2
    test3