Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better customization for slack messages #49

Closed
samrocketman opened this issue Feb 17, 2015 · 33 comments
Closed

Better customization for slack messages #49

samrocketman opened this issue Feb 17, 2015 · 33 comments

Comments

@samrocketman
Copy link
Member

Including the branch name in the slack notifications.

Also, not sure how to provide better customization of the slack notifications.

Contributions are welcome.

@DanaGoyette
Copy link

The most thorough way of allowing customization would be to extend "instant-messaging-plugin", the way "jabber-plugin" does:
https://github.com/jenkinsci/jabber-plugin
https://github.com/jenkinsci/instant-messaging-plugin

A simpler way would be to allow defining a custom message subject, with support for token macros.

Even more simply, if the plugin allows using build.getFullDisplayName() and/or build.getDescription(), other logic can take care of choosing the description. Currently, the slack plugin is hardcoded to use build.getProject().getName(), which is particularly uninformative with foldered jobs.

Example project:
project.getFullName(): "product1/head"
project.getFullDisplayName(): "product1 » head"
build.getFullDisplayName(): "product1 » head #NN"
build.getDescription(): (can be whatever I want, such as a list of platforms)
Current slack notification: "head - #NN". This format (with a dash) doesn't match anything in the Jenkins UI. Also, I have other jobs named "product2/head" and "product3/head".

@samrocketman
Copy link
Member Author

Feel free to make a contribution! I don't actively develop this plugin. I only manage pull requests and releases.

@samrocketman samrocketman changed the title Include the branch name in the slack notifications Better customization for slack messages Feb 19, 2015
@samrocketman
Copy link
Member Author

If you would like to be invited to https://jenkins-slack-plugin.slack.com/ for testing then just ask.

@digitalBush
Copy link

I was able to change the display by using the Build Name Setter Plugin. That might not be exacly what you are after, but it was enough for our needs.

@thorntonrose
Copy link

I would like to see this, too. I have users for whom a job name does not have much meaning. I need to post a message that they can relate to, like "Main TV 2.20 has been deployed."

@saigyo
Copy link

saigyo commented Apr 21, 2015

+1 I have the same use case as thorntonrose: deploy jobs which deploy specific versions of the product, and groups of people want to be notified of the availability of the new version.

@samrocketman
Copy link
Member Author

It's slated to be included. I'm leaving it open until around the 29th for code review.

@wickett
Copy link

wickett commented May 6, 2015

howdy! One thing I would like to customize is to add the username to the build output

right now at the end of the build I get this message in slack:

myapp - #123 Success after 1 min 01 sec (Open)

It would be nice to customize this to something like:

myapp - #123 Success after 1 min 01 sec [changes by: John Johnson] (Open)

@wickett
Copy link

wickett commented May 6, 2015

Another customization that would be nice is the ability to add slack emoji based on build status. ❌ for failure or ✅ for success.

@samrocketman
Copy link
Member Author

@wickett you can include the commit list with the slack message. That calls out which users made the changes. Is this not good enough?

@paulpv
Copy link

paulpv commented Jun 26, 2015

How to make a multi-line message?

@samrocketman
Copy link
Member Author

@paulpv #103 solves the issue you're asking about. It will be available in the 2.0 release. It has yet to be released.

@FaizVisram
Copy link

@samrocketman I'm currently using an environment variable for the custom message; the message itself has \n but in Slack it's being outputted as a literal \n. Any ideas on how to fix it?

@samrocketman
Copy link
Member Author

@FaizVisram According to the Slack API multiline messages documentation including a \n in the message should produce a newline. I wonder if there's some encoding going on in the background...

@samrocketman
Copy link
Member Author

I tested and confirmed your issue @FaizVisram. Please open a new issue describing the behavior. Perhaps a user will contribute a solution for you. Contributions are welcome.

@FaizVisram
Copy link

@samrocketman it seems as though the environment variable was taking it as a literal \n instead of parsing it as a new line. Had to re-write it to make it accept it as a new line. Thanks.

@samrocketman
Copy link
Member Author

@FaizVisram can you open an issue describing the fix?

@FaizVisram
Copy link

@samrocketman Created: Issue #135

@Nakilon
Copy link

Nakilon commented Oct 2, 2015

I've set Custom message to $MYVAR
In the Shell step I did export MYVAR=123
The bot said into the channel: $MYVAR ..(

@samrocketman
Copy link
Member Author

@Nakilon environment variables exported inside the shell don't get exported into the Jenkins runtime. You'd have to set a build parameter MYVAR or a global variable MYVAR. There won't ever be support for that in this plugin due to the design of Jenkins.

@Nakilon
Copy link

Nakilon commented Oct 3, 2015

OK, I got it.
I wished it was a way to leave a message for slack from the shell script.

@samrocketman
Copy link
Member Author

There is a way from the shell script. You could technically use curl to write to slack from a shell script. It wouldn't be via a Jenkins plugin but it's still do-able.

@mgedmin
Copy link
Member

mgedmin commented Jan 15, 2016

Including the branch name in the slack notifications.

I'm doing that by setting a custom message to Branch: $GIT_BRANCH, commit: $GIT_COMMIT:
ekrano nuotrauka is 2016-01-15 15-07-34

This produces Slack notifications like

ekrano nuotrauka is 2016-01-15 15-09-31

As you can see, there are some downsides:

  • $GIT_BRANCH tends to be something like "origin/feature-foo", and there's no way to strip off the "origin/" prefix.
  • $GIT_COMMIT is a full 40-character SHA-1 hash and there's no way to truncate it to the 1st 7 characters.

Any ideas about the best way to fix those? It's fine if the best way turns out to be "bug the git plugin maintainers to add additional environment variables $GIT_BRANCH_SHORT and $GIT_COMMIT_SHORT".

@Jaceken
Copy link

Jaceken commented Feb 19, 2016

@mgedmin
Thanks! Short and nice way to add branch and commit name.
For those who don't know where to find Include Custom Message fiels:
(you need to have Slack Notification Plugin installed in you jenkins)

  1. Enter job configuration screen
  2. In Slack Notifications section click Advanced
  3. Select Include Custom Message field

Now you can enter your custom message.

@ghost
Copy link

ghost commented Oct 15, 2016

The above comments does not work. In Slack it just displays the plain text as
Current Branch: $GIT_BRANCH

Can anyone guide whats wrong here?

@karankh
Copy link

karankh commented Apr 24, 2017

Where could I find full list of env. variables provides to us in jenkins for publishing on slack like -
GIT_BRANCH, GIT_CHANGE_AUTHOR
@Jaceken

@mgedmin
Copy link
Member

mgedmin commented Apr 25, 2017

Some of the variables (e.g. GIT_BRANCH) are provided by Jenkins plugins. I don't recall exactly which of the plugins I've used (GitHub Pull Request Builder plugin perhaps?).

IIRC I ran env as part of my Jenkins build in a shell script step to see the environment variables, some of which are set by Jenkins, and then tried the ones that seemed useful.

@MaikoHermans
Copy link

@Nakilon environment variables exported inside the shell don't get exported into the Jenkins runtime. You'd have to set a build parameter MYVAR or a global variable MYVAR. There won't ever be support for that in this plugin due to the design of Jenkins.

@samrocketman I'm currently using the environment injection plugin to inject an environment from a bash command. I can use this everywhere but when slack posts it's message it still won't use the variable it will just say $DIAWI_LINK. Any clue how to fix this? I would say that this should work

@samrocketman
Copy link
Member Author

This is a 2 year old issue. If you like, open a new issue with additional details for the current maintainers.

@yuri-karpovich
Copy link

@Nakilon environment variables exported inside the shell don't get exported into the Jenkins runtime. You'd have to set a build parameter MYVAR or a global variable MYVAR. There won't ever be support for that in this plugin due to the design of Jenkins.

@samrocketman I'm currently using the environment injection plugin to inject an environment from a bash command. I can use this everywhere but when slack posts it's message it still won't use the variable it will just say $DIAWI_LINK. Any clue how to fix this? I would say that this should work

Have you found a workaround?

@calbertts
Copy link

@Nakilon environment variables exported inside the shell don't get exported into the Jenkins runtime. You'd have to set a build parameter MYVAR or a global variable MYVAR. There won't ever be support for that in this plugin due to the design of Jenkins.

@samrocketman I'm currently using the environment injection plugin to inject an environment from a bash command. I can use this everywhere but when slack posts it's message it still won't use the variable it will just say $DIAWI_LINK. Any clue how to fix this? I would say that this should work

Have you found a workaround?

I'm looking for the same.

@VivaLaRobo
Copy link

@Nakilon environment variables exported inside the shell don't get exported into the Jenkins runtime. You'd have to set a build parameter MYVAR or a global variable MYVAR. There won't ever be support for that in this plugin due to the design of Jenkins.

@samrocketman I'm currently using the environment injection plugin to inject an environment from a bash command. I can use this everywhere but when slack posts it's message it still won't use the variable it will just say $DIAWI_LINK. Any clue how to fix this? I would say that this should work

Have you found a workaround?

I'm looking for the same.

any updates?

@dezren39
Copy link

#359 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests