KocproZ / jenkins-discord

A post-build plugin that sends the build status to a Discord channel.
MIT License
39 stars 36 forks source link

Accept environment variable as Webhook URL #16

Closed farahfa closed 6 years ago

farahfa commented 6 years ago

Hello,

Currently if I enter the webhook as a parameter or as an environment variable (secret text), the notification doesn't get sent out as it doesn't accept the URL.

ERROR: Build step failed with exception
java.net.MalformedURLException: no protocol: ${PST_DISCORD_JENKINS_CHANNEL}
    at java.net.URL.<init>(URL.java:593)
    at java.net.URL.<init>(URL.java:490)
    at java.net.URL.<init>(URL.java:439)
    at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:171)
Caused: java.lang.RuntimeException
    at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:183)
    at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:131)
    at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
    at nz.co.jammehcow.jenkinsdiscord.DiscordWebhook.send(DiscordWebhook.java:112)
    at nz.co.jammehcow.jenkinsdiscord.WebhookPublisher.perform(WebhookPublisher.java:104)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
    at hudson.model.Build$BuildExecution.cleanUp(Build.java:196)
    at hudson.model.Run.execute(Run.java:1771)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:421)
Build step 'Discord Notifier' marked build as failure
screen shot 2018-01-25 at 5 08 43 pm

It would be cool if that can get enabled as it will make it so much easier to integrate it to many jobs (and if the webhook URL changes, I'll only have to change it once from the credentials page).

jupjohn commented 6 years ago

I'll note it down and this should be added within the next few days.

azimonti commented 6 years ago

Hello, would it be possible to consider using the Credentials plugin directly as consumer? It would secure the storage of the webhook URL and be an elegant solution to the request.

jupjohn commented 6 years ago

I forgot to finish this off, but I'll go with @marcolinux's suggestion here. Bypasses unneeded steps.

azimonti commented 6 years ago

great thanks. If you prepare a pre-release hpi I can test it with pleasure.

farahfa commented 6 years ago

Well, for the sake of discussion, discord URL isn't necessarily a "secret". Which is why I suggested the ability to add it as an environment variable approach. Also, this way the developers have more freedom to define where they want to send the payload to.

farahfa commented 6 years ago

So lets say they want to send the payload to different discord channels on different Jenkins builds, they could put the webhook urls as a "choice parameter" and the plugin will pick up on that.

jupjohn commented 6 years ago

I would like to apologize for my absence and lack of care taken on this project. If one of you wants to submit a PR for this that would be great, otherwise I'm setting it up for release 1.3 when I get around to it. I'll definitely have a look at how I'd approach this within the next few days and re-evaluate the options.

Any changes and I'll let you all know.

jupjohn commented 6 years ago

I'm going to close this, see #25 for more details.