How to get the latest commit messages within a push and verify the message start with a certain regex pattern?

ε祈祈猫儿з 提交于 2019-12-10 11:55:21

问题


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

来源:https://stackoverflow.com/questions/52543525/how-to-get-the-latest-commit-messages-within-a-push-and-verify-the-message-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!