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

webhookURL via credentials #29

Open
Sector14 opened this issue Dec 18, 2020 · 5 comments
Open

webhookURL via credentials #29

Sector14 opened this issue Dec 18, 2020 · 5 comments

Comments

@Sector14
Copy link

Sector14 commented Dec 18, 2020

Is there any way to specify a credential ID in place of the webhookURL string or perhaps a env variable that could be made available via string credential binding?

I tried just entering a variable with the same name as defined in the credential binding plugin (which I used in shell scripts without issue) but the notification fails during build with:

java.net.MalformedURLException: no protocol: ${discordbuildwebhookurl}

Looking at the java file for the plugin, it appears to run env.expand(this.webhookURL) so I assume this is meant to be supported?

@Sector14
Copy link
Author

Closing, figured out where I was going wrong. The credential was only bound under the promotions environment and not the build environment which discord notifier is in.

@Sector14
Copy link
Author

Re-opening this issue: I've moved over to using pipeline and the discordSend pipeline step.

When using this step and "withCredentials", it appears the only way to use the credential for the webhookURL is via groovy string interpolation i.e:

discordSend webhookURL: "${discordbuildwebhookurl}",

Which results in a warning about insecure usage due to groovy string interpolation being used with a credential. Single quotes however does not work anymore as it looks like the pipeline version of this plugin does not perform env expansion of the webhookURL unlike the WebhookPublisher version which does:

DiscordWebhook wh = new DiscordWebhook(env.expand(this.webhookURL));

Is there a reason the expansion is not done? Is there a better way to make use of a credential for the webhookURL that does not involve groovy string interpolation?

@Sector14 Sector14 reopened this May 26, 2022
@KocproZ
Copy link

KocproZ commented May 31, 2022

I think env expansion in pipeline step was never brought up, that's why it's not there. I'm also not aware of a better way to use the credential.
While making the change should be straightforward, I don't have time to do that right now.
Pull requests are welcome.

@larsgerber
Copy link

Hello @KocproZ and @Sector14

I am new to Jenkins and was trying to resolve the following warning Warning: A secret was passed to "discordSend" using Groovy String interpolation, which is insecure. until I found this issue. I don't think this problem needs to be fixed, but I would have appreciated a short note in the readme. Should I create a PR for the updated documentation?

BR, Lars

@solonovamax
Copy link

Re-opening this issue: I've moved over to using pipeline and the discordSend pipeline step.

When using this step and "withCredentials", it appears the only way to use the credential for the webhookURL is via groovy string interpolation i.e:

discordSend webhookURL: "${discordbuildwebhookurl}",

the way I went about it was by declaring it in the env block:

env {
    DISCORD_WEBHOOK_URL = credentials('discord-webhook-url')
}

// ...

discordSend(webhookURL: env.DISCORD_WEBHOOK_URL)

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

No branches or pull requests

4 participants