Git Commit Message as an Environment Variable

30 views
Skip to first unread message

Jeremy Hartley

unread,
Nov 19, 2019, 9:53:52 AM11/19/19
to Jenkins Users
Hi,

I'm playing around a bit with Git environment variables to send to slack and would like to include the Git commit message. I don't see it available in the list here: https://wiki.jenkins.io/display/JENKINS/Git+Plugin#GitPlugin-Environmentvariables

Is there any way to send the Git commit message to slackSend as an environment variable in my pipeline?

Thanks

Jeremy

Daniel Beck

unread,
Nov 19, 2019, 3:34:55 PM11/19/19
to jenkins...@googlegroups.com
I have a (never released) plugin that integrates with the Jenkins changelog that does something like this: https://github.com/daniel-beck/changelog-environment-plugin

If you know enough Maven to build a plugin, this might work. The problem there is that the Jenkins built-in changelog doesn't handle PRs/branches well: The first builds always have no changelogs (since there's no reference to compare them to).

But I expect it's easier and more reliable to just call e.g. git show --no-patch --format='format:%s%n%n%b' and use its output (with some extra work to get around merge commits and such, depending on exactly what you want).

Eric Boehm

unread,
Nov 20, 2019, 5:44:17 PM11/20/19
to Jenkins Users
You could use groovy to collect the commit message from the ChangeSet and then put it in an environment variable.

Mark Waite

unread,
Nov 20, 2019, 6:37:44 PM11/20/19
to Jenkins Users
If it helps, I have an example that iterates over the changeset provided for a Pipeline job when running on a branch within a multibranch pipeline.

I believe it is limited to multibranch pipelines, but have not checked to be sure.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a0b485ff-8f48-4432-be5b-8a2d6af600a4%40googlegroups.com.


--
Thanks!
Mark Waite

Jeremy Hartley

unread,
Nov 21, 2019, 9:22:09 AM11/21/19
to Jenkins Users
Thanks Mark and Eric. I'll give this suggestion a try


On Thursday, November 21, 2019 at 12:37:44 AM UTC+1, Mark Waite wrote:
If it helps, I have an example that iterates over the changeset provided for a Pipeline job when running on a branch within a multibranch pipeline.

I believe it is limited to multibranch pipelines, but have not checked to be sure.

On Wed, Nov 20, 2019 at 3:44 PM 'Eric Boehm' via Jenkins Users <jenkins...@googlegroups.com> wrote:
You could use groovy to collect the commit message from the ChangeSet and then put it in an environment variable.

On Tuesday, November 19, 2019 at 9:53:52 AM UTC-5, Jeremy Hartley wrote:
Hi,

I'm playing around a bit with Git environment variables to send to slack and would like to include the Git commit message. I don't see it available in the list here: https://wiki.jenkins.io/display/JENKINS/Git+Plugin#GitPlugin-Environmentvariables

Is there any way to send the Git commit message to slackSend as an environment variable in my pipeline?

Thanks

Jeremy

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.


--
Thanks!
Mark Waite

Victor Martinez

unread,
Nov 22, 2019, 1:57:38 PM11/22/19
to Jenkins Users
If GitHub is the provider there is an inprogress PR to support it:
https://github.com/jenkinsci/pipeline-github-plugin/pull/65

Although I have not gone further to add some UTs yet though.
Reply all
Reply to author
Forward
0 new messages