jenkinsci / discord-notifier-plugin

A post-build plugin that sends the build status to a Discord channel.
https://plugins.jenkins.io/discord-notifier/
MIT License
50 stars 25 forks source link

Feature Request: multiple channels #8

Open hedin-hiervard opened 5 years ago

hedin-hiervard commented 5 years ago

It's currently not possible to notify 2 channels and to add the plugin to the post-build step twice (it's greyed out). I think it's possible from a Pipeline, but I don't have a Pipeline job. Maybe as a workaround, someone could provide a simple downstream Pipeline job that only takes the upstream job info and sends it to Discord?

KocproZ commented 5 years ago

Jenkins doesn't allow to add post build action more than once, and it can't be changed. I think that using pipeline is the only way to do this.

hedin-hiervard commented 5 years ago

I think that using pipeline is the only way to do this.

Can you please help me to create a pipeline job that is run after the main job and the only thing it does - sends the messages to the several Discord channels with build summary and artifact links?

melt7777 commented 5 years ago

If you do not want to make pipeline jobs,

You could use the post-build action "Build other projects" to have it call downstream freestyle or multi-configuration projects that have the Discord notifier as post-build actions.

Hope this is helpful.

Thanks for the great work!

~ melt getpimp.org | miner.farm

hedin-hiervard commented 5 years ago

If you do not want to make pipeline jobs,

You could use the post-build action "Build other projects" to have it call downstream freestyle or multi-configuration projects that have the Discord notifier as post-build actions.

Yeah, but will it have access to the artifacts of the upstream project?

melt7777 commented 5 years ago

Ah, I didn't think of that. Still learning! :)

KocproZ commented 5 years ago

Sadly I can't help you with creating such pipeline as I don't know how to do it :/

melt7777 commented 5 years ago

If you do not want to make pipeline jobs, You could use the post-build action "Build other projects" to have it call downstream freestyle or multi-configuration projects that have the Discord notifier as post-build actions.

Yeah, but will it have access to the artifacts of the upstream project?

You're right. I've explored a bit and it looks like you're going to need to do a pipeline for this one. The Journey into learning Groovy and making Pipelines stored in Github or other version control is a beautiful thing and makes life so much better. It's worth checking out.

Simply create a new pipeline and use the following snippet inside it. Note: I use the declarative pipeline syntax.

Here's a snippet with pipeline example for discordSend function:

node ('master') {
    stage ('Notify') {
def discordDesc = "Description here.."
(...)
discordSend description: discordDesc, 
                  footer: discordFooter, 
                  link: env.JOB_URL, 
                  result: currentBuild.currentResult, 
                  title: discordTitle, 
                  webhookURL: discordURL, 
                  successful: currentBuild.resultIsBetterOrEqualTo('SUCCESS'),
                  thumbnail: discordImage,
                  notes: "Here's some Notes! @<id_to_mention>"
   }
}

You can set the variables and then call discordSend however you like, or put the fields as inline strings.

bkostrowiecki commented 3 months ago

Maybe is it a good idea to have multiple Webhook URL fields in Discord Notifier post build action?