4
votes

I want to ignore running a Jenkins job if the commit message starts with a given string. I've tried adding "Additional Behaviours" and "Polling ignores commits with certain messages":

enter image description here

I.e. I want to ignore the job (which in my world means don't run the job) if the commit message starts with "doc!". I've tried several online regex matchers and I think that the regex of ^doc!.* is correct. But even though my commit messages does start with "doc!" the job is executed by Jenkins. What am I doing wrong?

2

2 Answers

4
votes

While @devanshu-dwivedi's answer might work my approach seem to work as well if I change my regex to:

(?s)^doc!.*

I don't exactly know why this is the case. The documentation says that using (?s) checks multiple comment lines in the commit messages. But without using (?s) it don't work for me even for single commits with a one line commit message.

0
votes

Jenkins Git plugin exposes you the environment variable GIT_COMMIT which of course, contains the current git commit hash. Use [Jenkins Conditional Step] and build a step which execute the following bash shell:

echo "==========================="

if [ "git show $GIT_COMMIT | grep ".doc" == false  ] ; then
    echo "pattern failed";
    exit 1
else
    echo "ok"
fi

echo "==========================="

And mark that if the shell fails, fail the build.