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

option to store the webhook url as a password. #267

Open
JuulRoelofs opened this issue Mar 22, 2022 · 6 comments
Open

option to store the webhook url as a password. #267

JuulRoelofs opened this issue Mar 22, 2022 · 6 comments

Comments

@JuulRoelofs
Copy link

What feature do you want to see added?

In the current configuration the webhook url(s) can be globally as plain text.
When configuring the job the name of the webhook url can be filled in.
After saving the url is exposed in the job.
It would be great to have the webhook URL stored as a password and not exposed to all Jenkins users.

Upstream changes

No response

@damianszczepanik
Copy link
Member

not sure about your intention - password to what ?

@mPokornyETM
Copy link

When you need to store so passwords webhooks ... you can use jenkins credentials as well. And then use withCredential function to store it in jenkins variable. This should work also for this plugin

@giridhar08
Copy link

giridhar08 commented Mar 31, 2023

I am looking to pass secret text "webHookURL" inside the options block to set url value inside office365ConnectorWebhooks as shown below

pipeline {
agent none

options {
    
    office365ConnectorWebhooks([[
        name: 'myConnector',
        startNotification: true,
        url: webHookURL,
        notifyFailure: true,
        notifySuccess: true
    ]])
    }
}

Tried using withCredentials block but got error that withCredentials cannot be used inside options block.

Any idea how to set secret text value in this case

@damianszczepanik
Copy link
Member

@kaedwen
Copy link

kaedwen commented Jul 31, 2023

Hey, I have the same problem. I need to configure multiple webhook urls and want them to be configured centrally. Using the global jenkins section is capable for one webhook only. So my idea was to read the webhook url from a credential during the pipeline setup in the options block like this

The teams-channel-1 webhook is a secret text

  options {
    office365ConnectorWebhooks([[
      name: 'Teams Test',
      url: credentials('teams-channel-1'),
      startNotification: true,
      notifySuccess: true,
      notifyAborted: false,
      notifyNotBuilt: false,
      notifyUnstable: true,
      notifyFailure: true,
      notifyBackToNormal: true,
      notifyRepeatedFailure: false
    ]])
  }

But this fails with java.lang.UnsupportedOperationException: no known implementation of class java.lang.String is using symbol ‘credentials’

Next idea was to use an environment block and reference the env inside the options block, but does not work either.

  environment {
    CHANNEL_WEBHOOK = credentials('teams-channel-1')
  }

  options {
    office365ConnectorWebhooks([[
      name: 'Teams Test',
      url: env.CHANNEL_WEBHOOK,
      startNotification: true,
      notifySuccess: true,
      notifyAborted: false,
      notifyNotBuilt: false,
      notifyUnstable: true,
      notifyFailure: true,
      notifyBackToNormal: true,
      notifyRepeatedFailure: false
    ]])
  }

Do you have any idea, or ist it possible to define multiple webhooks in the global jenkins ui?

@faandg
Copy link

faandg commented Apr 16, 2024

The problem is that jenkins or the credentials binding plugin do not allow using a credentials block in the options block, so you cannot reference the webhook URL as a jenkins secret here.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 14: Options definitions cannot have blocks @ line 14, column 9.
withCredentials([string(credentialsId: 'wh-teams-notify', variable: "WH_URL")]) {

You can use office365ConnectorSend in a post { always } step (credential blocks DO work in post steps), but office365ConnectorSend does not have the same configuration as office365ConnectorWebhooks so as of date there is no good solution yet imo.
With office365ConnectorSend you'd be missing out on this config:

      notifySuccess: true,
      notifyAborted: false,
      notifyNotBuilt: false,
      notifyUnstable: true,
      notifyFailure: true,
      notifyBackToNormal: true,
      notifyRepeatedFailure: false

You can try to map it on the post conditions: always, changed, fixed, regression, aborted, failure, success, unstable, unsuccessful, and cleanup. but it's not really the same...

Ideally you'd be able to use office365ConnectorWebhooks in the options block to specify your webhook URL as a secret because that's what it is, especially without HMAC.

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

6 participants