I tried to get the git commit message in jenkinsfile and prevent the build based on commit message.
env.GIT_COMMIT doesn't return the commit details in jenkinsfile.
How to get the git latest commit message and prevent the jenkins build if the commit message contains [ci skip] in it?
I think you could easily do that in multi branch pipeline job configuration Branch Sources > Additional Behaviours > Polling ignores commits with certain messages
I had the same issue. I'm using pipelines. I solved this issue by implementing a shared library.
The code of the library is this:
Then, in my Jenkinsfile:
As you can see, the build is marked as
NOT_BUILT
. You can change it toABORTED
if you prefer, but it cannot be set toSUCCESS
because a build result can only get worseThe build will pass when [ci skip] is provided in the last git log, but will not run the actual build code (the replacement to the first echo statement)
As of today, it's quite easy to achieve. The interesting line is the
extension
namedMessageExclusion
whereexcludedMessage
accepts a regular expression.