Giter VIP home page Giter VIP logo

jenkinsci / generic-webhook-trigger-plugin Goto Github PK

View Code? Open in Web Editor NEW
396.0 11.0 157.0 1.34 MB

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.

Home Page: https://plugins.jenkins.io/generic-webhook-trigger

Shell 0.29% Java 60.31% HTML 0.28% Gherkin 38.68% Groovy 0.43%
webhook trigger jenkins-plugin jira github gitlab bitbucket bitbucket-server notification parameter

generic-webhook-trigger-plugin's Introduction

Generic Webhook Trigger Plugin

Build Status

This is a Jenkins plugin that can:

  1. Receive any HTTP request, JENKINS_URL/generic-webhook-trigger/invoke
  2. Extract values
  • From POST content with JSONPath or XPath
  • From the query parameters
  • From the headers
  1. Trigger a build with those values contribute as variables

There is an optional feature to trigger jobs only if a supplied regular expression matches the extracted variables. Here is an example, let's say the post content looks like this:

{
  "before": "1848f1236ae15769e6b31e9c4477d8150b018453",
  "after": "5cab18338eaa83240ab86c7b775a9b27b51ef11d",
  "ref": "refs/heads/develop"
}

Then you can have a variable, resolved from post content, named ref of type JSONPath and with expression like $.ref . The optional filter text can be set to $ref and the filter regexp set to ^(refs/heads/develop|refs/heads/feature/.+)$ to trigger builds only for develop and feature-branches.

There are more examples of use cases here.

Video showing an example usage:

Generic Webhook Trigger Usage Example

It can trigger on any webhook, like:

The original use case was to build merge/pull requests. You may use the Git Plugin as described in this blog post to do that. There is also an example of this on the Violation Comments to GitLab Plugin page.

You may want to report back to the invoking system. HTTP Request Plugin is a very convenient plugin for that.

If a node is selected, then all leafs in that node will be contributed. If a leaf is selected, then only that leaf will be contributed.

Trigger only specific job

When using the plugin in several jobs, you will have the same URL trigger all jobs. If you want to trigger only a certain job you can:

  • Use the token-parameter have different tokens for different jobs. Using only the token means only jobs with that exact token will be visible for that request. This will increase performance and reduce responses of each invocation.
  • Or, add some request parameter (or header, or post content) and use the regexp filter to trigger only if that parameter has a specific value.

Token parameter

There is a special token parameter. When supplied, the invocation will only trigger jobs with that exact token. The token also allows invocations without any other authentication credentials.

In version 2.x of the plugin it no longer supports specifying the token outside of the plugin in BuildAuthorizationToken.

Parameter

The token can be supplied as a:

  • Request parameter:

    curl -vs "http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=abc123" 2>&1

  • Token header:

    curl -vs -H "token: abc123" "http://localhost:8080/jenkins/generic-webhook-trigger/invoke" 2>&1

    • It will also detect X-Gitlab-Token.
  • Authorization header of type Bearer :

    curl -vs -H "Authorization: Bearer abc123" "http://localhost:8080/jenkins/generic-webhook-trigger/invoke" 2>&1

Dry run

The dry run feature enables a user to test the plugin without actually triggering any jobs.

Dry run is enabled by supplying the gwt-dry-run: true header.

curl -v -H "gwt-dry-run: true"\
  "http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=abc123"

Cache jobs

In large installations, it may take some time to retrieve all configured jobs. The plugin solves this by keeping track of configured jobs using ItemListener. This will only be used in invocations where a token is supplied so using token that is recommended for performance.

Trigger exactly one build

Until version 1.85.2 of this plugin, it would batch builds with same parameters. The 1.86.0 adds an option, allowSeveralTriggersPerBuild, that, if checked, will keep this behavior. If not checked, the plugin will trigger exactly one job when invoked.

Whitelist hosts

Whitelist can be configured in Jenkins global configuration page. The whitelist will block any request to the plugin that is not configured in this list. The host can be empty to allow any, static IP, CIDR or ranges:

  • 1.2.3.4
  • 2.2.3.0/24
  • 3.2.1.1-3.2.1.10
  • 2001:0db8:85a3:0000:0000:8a2e:0370:7334
  • 2002:0db8:85a3:0000:0000:8a2e:0370:7334/127
  • 2001:0db8:85a3:0000:0000:8a2e:0370:7334-2001:0db8:85a3:0000:0000:8a2e:0370:7335

The hosts can optionally also be verified with HMAC.

Whitelist

Troubleshooting

If you want to fiddle with the plugin, you may use this repo: https://github.com/tomasbjerre/jenkins-configuration-as-code-sandbox

If you are fiddling with expressions, you may want to checkout:

It's probably easiest to do with curl. Given that you have configured a Jenkins job to trigger on Generic Webhook, here are some examples of how to start the jobs.

curl -vs "http://localhost:8080/jenkins/generic-webhook-trigger/invoke" 2>&1

This should start your job, if the job has no token configured and no security enabled. If you have security enabled you may need to authenticate:

curl -vs "http://theusername:thepasssword@localhost:8080/jenkins/generic-webhook-trigger/invoke" 2>&1

If your job has a token you don't need to supply other credentials. You can specify the token like this:

curl -vs "http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=TOKEN_HERE" 2>&1

Please keep in mind, using a token always runs the triggered jobs with SYSTEM privileges.

If you want to trigger with token and some post content, curl can dot that like this.

curl -v -H "Content-Type: application/json" -X POST -d '{ "app":{ "name":"some value" }}' "http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=TOKEN_HERE"

Screenshots

Generic trigger

Default values

The plugin can be configured with default values. Like below:

Default Value

But if you execute the job manually (or replay a pipeline), this default value will not be used. Because the plugin will not be invoked at all. You can solve this by checking the "This job is parameterized" and add a parameter with the same name as the one you configured in the plugin. Like this:

Default Value

Now this default value will be used both when you trigger the job manually, replaying pipeline, and when you trigger it with the plugin!

Pre build step

If you need the resolved values in pre build steps, like git clone, you need to add a parameter with the same name as the variable.

Parameter

Job DSL Plugin

This plugin can be used with the Job DSL Plugin. There is also an example int he Violation Comments to GitLab Plugin wiki page.

Job DSL supports injecting credenials when processing the DSL. You can use that if you want the token to be set from credentials.

pipelineJob('Generic Job Example') {
 parameters {
  stringParam('VARIABLE_FROM_POST', '')
 }

 triggers {
  genericTrigger {
   genericVariables {
    genericVariable {
     key("VARIABLE_FROM_POST")
     value("\$.something")
     expressionType("JSONPath") //Optional, defaults to JSONPath
     regexpFilter("") //Optional, defaults to empty string
     defaultValue("") //Optional, defaults to empty string
    }
   }
   genericRequestVariables {
    genericRequestVariable {
     key("requestParameterName")
     regexpFilter("")
    }
   }
   genericHeaderVariables {
    genericHeaderVariable {
     key("requestHeaderName")
     regexpFilter("")
    }
   }
   token('abc123')
   tokenCredentialId('')
   printContributedVariables(true)
   printPostContent(true)
   silentResponse(false)
   shouldNotFlatten(false)
   regexpFilterText("\$VARIABLE_FROM_POST")
   regexpFilterExpression("aRegExp")
  }
 }

 definition {
  cps {
   // Or just refer to a Jenkinsfile containing the pipeline
   script('''
    node {
     stage('Some Stage') {
      println "VARIABLE_FROM_POST: " + VARIABLE_FROM_POST
     }
    }
   ''')
   sandbox()
  }
 }
}

Pipeline

When configuring from pipeline (not multibranch pipeline), that pipeline needs to run once, to apply the plugin trigger config, and after that this plugin will be able to trigger the job. This is how Jenkins works, not something implemented in this plugin.

This means that if you create a pipeline like this:

Parameter

You need to run it once to have the properties applied. You can verify that the properties has been applied by opening the configuration view (or view configuration if using multibranch pipeline) of the job. You will see that the "Generic Webhook Trigger" is checked and will now have values from your pipeline. Like this:

Parameter

You can avoid having to run twice, by using Job DSL and have Job DSL create pipeline jobs with the plugin configured in that DSL.

This plugin can be used in the jobs created by the Pipeline Multibranch Plugin. If you are looking for a way to trigger a scan in the Pipeline Multibranch Plugin you can use the Multibranch Scan Webhook Trigger Plugin.

You can use the credentials plugin to provide the token from credentials.

withCredentials([string(credentialsId: 'mycredentialsid', variable: 'credentialsVariable')]) {
 properties([
  pipelineTriggers([
   [$class: 'GenericTrigger',
    ...
    token: credentialsVariable,
    ...
   ]
  ])
 ])
}

Perhaps you want a different token for each job.

 properties([
  pipelineTriggers([
   [$class: 'GenericTrigger',
    ...
    token: env.JOB_NAME,
    ...
   ]
  ])
 ])

Or have a credentials string prefixed with the job name.

withCredentials([string(credentialsId: 'mycredentialsid', variable: 'credentialsVariable')]) {
 properties([
  pipelineTriggers([
   [$class: 'GenericTrigger',
    ...
    token: env.JOB_NAME + credentialsVariable,
    ...
   ]
  ])
 ])
}

With a scripted Jenkinsfile like this:

node {
 properties([
  pipelineTriggers([
   [$class: 'GenericTrigger',
    genericVariables: [
     [key: 'ref', value: '$.ref'],
     [
      key: 'before',
      value: '$.before',
      expressionType: 'JSONPath', //Optional, defaults to JSONPath
      regexpFilter: '', //Optional, defaults to empty string
      defaultValue: '' //Optional, defaults to empty string
     ]
    ],
    genericRequestVariables: [
     [key: 'requestWithNumber', regexpFilter: '[^0-9]'],
     [key: 'requestWithString', regexpFilter: '']
    ],
    genericHeaderVariables: [
     [key: 'headerWithNumber', regexpFilter: '[^0-9]'],
     [key: 'headerWithString', regexpFilter: '']
    ],

    causeString: 'Triggered on $ref',

    token: 'abc123',
    tokenCredentialId: '',

    printContributedVariables: true,
    printPostContent: true,

    silentResponse: false,
    
    shouldNotFlatten: false,

    regexpFilterText: '$ref',
    regexpFilterExpression: 'refs/heads/' + BRANCH_NAME
   ]
  ])
 ])

 stage("build") {
  sh '''
  echo Variables from shell:
  echo ref $ref
  echo before $before
  echo requestWithNumber $requestWithNumber
  echo requestWithString $requestWithString
  echo headerWithNumber $headerWithNumber
  echo headerWithString $headerWithString
  '''
 }
}

With a declarative Jenkinsfile like this:

pipeline {
  agent any
  triggers {
    GenericTrigger(
     genericVariables: [
      [key: 'ref', value: '$.ref']
     ],

     causeString: 'Triggered on $ref',

     token: 'abc123',
     tokenCredentialId: '',

     printContributedVariables: true,
     printPostContent: true,

     silentResponse: false,
     
     shouldNotFlatten: false,

     regexpFilterText: '$ref',
     regexpFilterExpression: 'refs/heads/' + BRANCH_NAME
    )
  }
  stages {
    stage('Some step') {
      steps {
        sh "echo $ref"
      }
    }
  }
}

It can be triggered with something like:

curl -X POST -H "Content-Type: application/json" -H "headerWithNumber: nbr123" -H "headerWithString: a b c" -d '{ "before": "1848f12", "after": "5cab1", "ref": "refs/heads/develop" }' -vs "http://admin:admin@localhost:8080/jenkins/generic-webhook-trigger/invoke?requestWithNumber=nbr%20123&requestWithString=a%20string"

And the job will have this in the log:

Contributing variables:

    headerWithString_0 = a b c
    requestWithNumber_0 = 123
    ref = refs/heads/develop
    headerWithNumber = 123
    requestWithNumber = 123
    before = 1848f12
    requestWithString_0 = a string
    headerWithNumber_0 = 123
    headerWithString = a b c
    requestWithString = a string

Plugin development

More details on Jenkins plugin development is available here.

A release is created like this. You need to clone from jenkinsci-repo, with https and have username/password in settings.xml.

mvn release:prepare release:perform

generic-webhook-trigger-plugin's People

Contributors

absoluteother avatar basil avatar daniel-beck-bot avatar daninst84 avatar gmanfunky avatar jekader avatar juanpablo-santos avatar limejuny avatar markewaite avatar mb388a avatar mterzo avatar rene00 avatar robert-shade avatar thetekton avatar tomasbjerre avatar tristanmcpherson avatar twinderw avatar vtsykun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

generic-webhook-trigger-plugin's Issues

Did not find any jobs to trigger!

Apr 29, 2017 8:36:42 AM org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver doInvoke
INFO: Did not find any jobs to trigger! The user invoking /generic-webhook-trigger/invoke must have read permission to any jobs that should be triggered.

I use postman request everything is ok,but gitlab webhook error.
What is the problem , thanks.

When token used, only trigger if token supplied

Currently, if token supplied, the implementation uses that token to authenticate. And that will make the job visible for that request. But! The job might be visible without authentication or the invoke may use something like http://user:pass@jenkins/ and be authenticated without the token...

I'm considering changing the behavior so that if a token is configured in the job, then the job will only trigger if that token is supplied. Even if the invoke has enough credentials to see the job without supplying the token.

The problem with the current implementation is that someone can accidentally trigger a lot of jobs if invoking the plugin with credentials that makes a lot of jobs visible.

How to specify a specific branch๏ผŸ

Hello!
When I use this plugin๏ผŒAnd I want to specify a specific branch! But I don't know how to set up!

Generic Webhook Trigger | ย 
ย  | Post content parameters |
ย  | Header parameters |
ย  | Request parameters |
Optional filter
ย  | Expression | ย 
ย  | Text | ย 

Can you write any document to help us? Thanks!

Redundant information on job responses

Hi,

currently a generic-webhook trigger invocation returns too much information, as it contains the response of all jobs, whether they're "triggered or not" by the generic webhook. Those "not triggered" jobs include the resolved variables, which doesn't add anything, as they haven't been used because the job hasn't been triggered.

Furthermore, for a given invocation, the resolved variables are always the same for all the pinged jobs, so they could be extracted to their own variable on GenericWebHookRequestReceiver, and returned only once.

Also, as of 1.22 onwards, because of the actual json/xml being contributed as a resolved variable, it also means that the resolved variables content is returned twice, for each job, first one consisting of the sum of each "json/xml leaf" variable, and the other one because of the contributed variable (although I suppose we can manually remove the contributed variable on the pipeline from the triggered jobs).

Why is this a problem? We're using gitea's webhooks to trigger some jobs on jenkins and because all of this, we're beginning to have some webhook responses which are more than 65K characters, which is the maximum allowed by the column which stores the webhook response, so Gitea doesn't store the response, doesn't swallow the unexpected error and doesn't update their appropiate tbale's row, so the webhook remains as not sent, so, on the next webhook call, the webhook is called again, and again, etc. This has become more pressing when we updated to latest version of the plugin, which doubled the output's response.

I understand we've most probably hit a bug on the gitea side, but it would be nice to be able to control the amount of information returned by the generic-webhook-trigger-plugin, or at least to have not returning duplicated info. I can prepare a PR for the latter if needed, as I'm not really sure how to the former could be accomplished..

br,
juan pablo

Which version to use for Jenkins 2.0

Hi,

I have been using your plugin and I used it on my personal jenkins server which works great and does exactly what I need it to do, However in my work we only have Jenkins 2.0.. is there a version of the plugin that will support this? I have 1.20 installed and it doesnt recognize the input with job DSL api creation through groovy

Thanks
Carl

Can we use environment variables in regexpFilterExpression?

I am trying to set a dynamic filter based on the repo and the job name (we use same Jenkinsfile in all the repos) with following settings:

regexpFilterText: '$repo',
regexpFilterExpression: '/${env.JOB_NAME}.split("/")[1]/g'

The $repo is correctly set to the repo name e.g. template-service and I want to match it with the repo name in the job e.g. ORG/template-service/master. Even with this filter, the webhook is triggering all the jobs. I tried changing '${env.JOB_NAME}' to 'env.JOB_NAME' but that does not work either. Is it possible to use environment variables in regexpFilterExpression? Why is this filter triggering all the jobs?

Ability to add multiple Optional Filters

Would it be possible to add multiple optional filters so that the plugin could prevent builds for multiple scenarios? The same way we could add multiple post content parameters?

  • Specific Events
  • Specific users
  • The combination of both, I want to prevent builds on commits made by User X and to prevent builds when a Tag event is sent
    This would allow fine grain situations on when to trigger a legitimate build.

Header Variables cannot be reused through several webhook triggered jobs

i.e., unit test reproducing the issue (adapted from VariablesResolverHeaderTest):

  @Test
  public void testHeaderResolvesCanBeReused() throws Exception {
    String postContent = null;

    List<GenericVariable> genericVariables = newArrayList();

    Map<String, String[]> parameterMap = new HashMap<>();
    List<GenericRequestVariable> genericRequestVariables = new ArrayList<>();

    Map<String, Enumeration<String>> headers = new HashMap<>();
    headers.put("someparam", enumeration("some value"));

    List<GenericHeaderVariable> genericHeaderVariables = new ArrayList<>();
    genericHeaderVariables.add(new GenericHeaderVariable("someparam", null));
    Map<String, String> variables =
            new VariablesResolver(
                    headers,
                    parameterMap,
                    postContent,
                    genericVariables,
                    genericRequestVariables,
                    genericHeaderVariables)
                .getVariables();

        assertThat(variables) //
            .containsEntry("someparam", "some value") //
            .hasSize(2);

    variables =
            new VariablesResolver(
                    headers,
                    parameterMap,
                    postContent,
                    genericVariables,
                    genericRequestVariables,
                    genericHeaderVariables)
                .getVariables();

        assertThat(variables) //  --> this one fails, variables is empty here
            .containsEntry("someparam", "some value") //
            .hasSize(2);
  }

  private Enumeration<String> enumeration(final String... string) {
    return new Enumeration<String>() {
      private int i = 0;

      @Override
      public String nextElement() {
        return string[i++];
      }

      @Override
      public boolean hasMoreElements() {
        return i < string.length;
      }
    };
  }

As title says, header variables cannot be reused through several webhook triggered jobs. This is because at RequestHeaderResolver#L30 and onwards, the Enumeration is first readed and consumed to set the header variable for the first job. When the second job arrives to the same code, it obtains the same Enumeration consumed on the first run, so headerEnumeration.hasMoreElements() returns false and doesn't set the header variable.

Suggested approachs to fix this:

  • Convert the Enumeration to a List, work with it, and then create a new Enumeration from this List and put it back on the incomingHeaders variable (PR with this approach following shortly, as there is far less code modified)
  • On GenericWebHookRequestReceiver, store the headers as Map <String, List<String>> instead of Map <String, Enumeration<String>>. Propagate this change throughout the plugin

Receive additional info after job trigger

Now we get following data back from generic-webhook-trigger-plugin:

{
    "status": "ok",
    "data": {
        "triggerResults": {
            "jenkins-test": "OK"
        }
    }
}

It would be great to be able to configure more information, as example queueId or even more

Wanna get all request body that payload body including null value

I wanna receive all request body including null value for matching secret key

i tried below code for getting request body that payload

properties([
            pipelineTriggers([
                [$class: 'GenericTrigger',
                     genericVariables: [
                             [expressionType: 'JSONPath', key: 'body', value: '$'],
                             [expressionType: 'JSONPath', key: 'reference', value: '$.ref'],
                             [expressionType: 'JSONPath', key: 'referenceType', value: '$.ref_type']
                     ],
                     genericHeaderVariables: [
                             [key: 'X-GitHub-Event', regexpFilter: ''],
                             [key: 'X-Hub-Signature', regexpFilter: '']
                     ],

                     regexpFilterText: '',
                     regexpFilterExpression: ''
                ]
            ])
    ])

...


def payLoad = "${env.body}"

echo "${payLoad}'

result is not including null value

The expected value contains null, but does not match the X-path-signature value.

How to get request body including null value

cf) The null values โ€‹โ€‹are homepage and mirror-url

Enhancement: allow request headers to be set as variables too

it would be useful to also set variables from request headers, f.ex.,

  • Gogs' webhooks are capable of sending a custom header, secret, which can be used at jenkins' side to see if the request cames from that webhook (is legit), or not
  • also Gogs' webhooks send the event that triggered the webhook on a request header. Different events produce different payloads

On the UI side, as headers and request parameters would be treated essentially the same, maybe the current request parameter variable field could be reused? that is, if the variable isn't found as a request parameter, then look for it on the request headers? Or maybe is better to clearly separate one from another?

Turn 'Optional filter' to negative matching

If i use the webplugin with an Optional filter this option is allways positive.
If the value does match the expression the build is trigert.

But i like to be able to state under witch condition i like to skip the build.
Say if user is 'build' i like to skip the build. Any other user is fine.

How do i accomplish this ?

Header parameter not available for Optional Filter text

Thanks a ton for this project..

I will dive deeper, but after a couple hours I wanted to file an issue with a simplified test case.

I am able to get Request Parameters parsed into the Text for the Optional Filter, but it seems like the HTTP header variable isn't getting interprolated.

For example, webhook configuration like this:
image

But a curl like
curl -v -H 'TESTHEADER: testValue' https://example.com/generic-webhook-trigger/invoke?token= GABE

Returns a json response without the parameter substution.
image

I re-configured it with Request Parameter and it gets replaced and matched as expected.

I'm actually trying to match X-GitHub-Event: pull_request in my Optional Filter, but I whittled it down to a simple header without dashes for this test.

I'll go looking at the test code next, and maybe even go grab a JDK to possibly help. But i wanted to check if anything seemed out of sorts to others too.

Thanks again for the project!

GitHub webhooks firing up twice and Build is getting triggered.

I have configured the Jenkins job to ignore specific commits from specific user, I am looking that github is triggering twice the same hook with the same payload, when this gets to jenkins, it gets stopped on its tracks the first time but not the second time, leading to a build.
image

image

Please note the timestamps for both, they happen within milliseconds.

Lacks job selection

If you have 2+ projects on Jenkins and call the URL to invoke, it will build all projects with this plugin enabled. Should be a parameter to set which job to build.

Do not show received payload in Jenkins job

How should I configure generic-webhook-trigger-plugin to avoid showing

Generic Cause
GenericWebhookEnvironmentContributor Received:
{
  // my request data here, I would like to hide it
}

"This project is parameterized" parameters are being ignored if triggered

Our SCM tool is sending PR events to trigger our builds but the default parameters that we set get ignored and are not present in the environment.

  1. Create Pipeline Job
  2. Check "This project is parameterized"
  3. Add dummy parameter
  4. setup generic webhook trigger with your repo
  5. Manually build project - pass: dummy parameter is present
  6. Trigger the job with a commit - fail: dummy parameter is not present

Workaround:
Define all parameters in generic webhook trigger section... this means we have to define everything twice

Caused by: java.lang.NoSuchMethodError: hudson.util.HttpResponses.okJSON

When I push with curl, I get this error response as html :

Caused by: java.lang.NoSuchMethodError: hudson.util.HttpResponses.okJSON(Ljava/util/Map;)Lorg/kohsuke/stapler/HttpResponse;
        at org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver.doInvoke(GenericWebHookRequestReceiver.java:96)
        at org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver.doInvoke(GenericWebHookRequestReceiver.java:57)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298)
        at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161)
        at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96)
        at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:121)
        at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
        at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)

Windows 7
maven 3.3
java 7

Thanks in advance.

replace "-" characters on header variable names

Most headers include a - character in its name (i.e., content-type), which gets published on the pipeline as content-type, which isn't a valid groovy name.

PR following, replacing "-" with "_" on header variable names (maybe it should be done for request params too?)

NullPointerException at GenericTriggerResults (version 1.25)

Groovy code:
pipelineTriggers([[ $class: 'GenericTrigger', genericVariables: [ // Bitbucket EventPayloads: https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html#EventPayloads-Push [key: 'EVENT_REPOSITORY_NAME', value: '$.repository.full_name', expressionType: 'JSONPath'], [key: 'EVENT_PUSH_TYPE', value: '$.push.changes[0].new.type', expressionType: 'JSONPath'], [key: 'BRANCH_OR_TAG', value: '$.push.changes[0].new.name', expressionType: 'JSONPath'], ], genericRequestVariables: [ [key: 'WAR_PROFILE', regexpFilter: ''], [key: 'EXEC_DEPLOY', regexpFilter: ''], [key: 'UPDATEBUILD', regexpFilter: ''], ], regexpFilterText: '$EVENT_PUSH_TYPE', regexpFilterExpression: 'tag' ]

Response Body:
{ "status": "ok", "data": { "triggerResults": { "pipeline-webhook-test": "Exception occurred, full stack trace in Jenkins server log. Thrown in: org.jenkinsci.plugins.gwt.GenericTriggerResults:21", } } }

Jenkins Log:
java.lang.NullPointerException at org.jenkinsci.plugins.gwt.GenericTriggerResults.<init>(GenericTriggerResults.java:21) at org.jenkinsci.plugins.gwt.GenericTrigger.trigger(GenericTrigger.java:118) at org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver.doInvoke(GenericWebHookRequestReceiver.java:87) at org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver.doInvoke(GenericWebHookRequestReceiver.java:56) at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627) at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:343) at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:184) at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:117) at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:129) at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58) at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:715) at org.kohsuke.stapler.Stapler.invoke(Stapler.java:845) at org.kohsuke.stapler.MetaClass$10.dispatch(MetaClass.java:374) at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:715) at org.kohsuke.stapler.Stapler.invoke(Stapler.java:845) at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649) at org.kohsuke.stapler.Stapler.service(Stapler.java:238) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650) at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:135) at hudson.plugins.greenballs.GreenBallFilter.doFilter(GreenBallFilter.java:59) at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:132) at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:138) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) at org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver.process(GenericWebHookRequestReceiver.java:125) at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:58) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84) at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51) at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87) at jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117) at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87) at

Logic in "Optional filter" text field [question]

I would like to add some logic by concatenating strings/variables in Optional filter text field.

For example:

  • concatenate string w/ variable $FILTER_VAR'customstring'
  • concatenate variables $FILTER_VAR$ANOTHER_VAR

Is it possible or I can workaround this?

Add suport for Authorization Bearer

It should be possible to pass token in headers: Authorization : Bearer <token-goes-here> to keep it away from logs and let invoking application know this should be secret (and don't include it in output).

Trigger Specific Job based on Payload

The plugin works great. Let say I have 5 jobs using this plugin. Instead of triggering all the jobs can I control based on the event /payload I receive?

Also, does this plugin execution can handle huge list of events fired ( example: 100 in a min) ?

If the plugin does not lose the received payload during heavy load, can I see the pending requests in Jenkins/ Plugin configuration?

Once again thanks

JSONPath processing seems to not handle "," operator

Using the example of a GitHub PushEvent (1)

I can create a "Post content parameters" entry as such:

Variable: gitFilesModified
Expression: $.commits[*].modified[*]

And the Environment variable in the run "gitFilesModified_0" is set as expected.

However, if I try to create a variable for all files affected:

Variable: gitFilesAffected
Expression: $.commits[*].modified,added,removed[*]

No environment variables starting with "gitFilesAffected" are created at all.

Testing with jsonpath.com, this doesn't seem to be a problem with the path expression itself.

Cheers
Darren

(1) https://developer.github.com/v3/activity/events/types/#pushevent

How to access request header variables?

I am trying to access request header variable, X-GitHub-Event, but is always coming up as null. Here is the snippet of my code to extract 'event' variable from header but is not working:

properties([
pipelineTriggers([
[$class: 'GenericTrigger',
genericVariables: [
[expressionType: 'JSONPath', key: 'owner', value: '$.repository.owner.login'],
[expressionType: 'JSONPath', key: 'repo', value: '$.repository.name'],
[expressionType: 'JSONPath', key: 'username', value: '$.sender.login']
],
genericHeaderVariables: [
[key: 'event', regexpFilter: '/X-GitHubEvent:(.*)/g']
],
regexpFilterText: '',
regexpFilterExpression: ''
]
])
])

Contribute all leafs in node, if node is selected by expression

Hi,

Currently, if a JSONPath expression selects a node rather than a leaf, then no matter what, it gets converted to a String. This is because on VariableResolver#addPostContentParameters, the call to the filter methods uses a toString on the resolved variable (which, in JSONPath can also be a map, if the expression resolves to a node instead of a leaf)

For large pipelines, which use a lot of JSONPath params, it would be nice to have one or two variables representing JSONPath nodes, instead of having one variable for each needed value (as a side effect, this would also allow to access the whole webhook payload). F.ex, inside the pipeline is really easy to do something like

"""
Dear email template,
<a href="$sender.email">$sender.full_name"</a> has come to known blablabla
"""

and it's much more manageable if the job has only one or a couple of JSONPath params rather than 10 or 12.

It seems that to achieve this only requires a couple of changes on VariableResolver:

  1. on VariableResolver#L62, the call to filter should be changed to:
map.put(gv.getKey() + "_" + i, filter(o, gv.getRegexpFilter()));
  1. replace the filter method with:
private Object filter(Object string, String regexpFilter) {
    if( string instanceof String ) {
        if (string == null || regexpFilter == null || regexpFilter.isEmpty()) {
          return string;
        }
        return string.replaceAll(regexpFilter, "");
    } else {
        LOGGER.info( "NOT filtering " + string )
        return object;
    }
}

As noted above, the ability to filter values on the parameter would be lost for nodes, although that functionality wouldn't be really useful for them anyway.

WDYT?

thanks,
juan pablo

How to Generic Trigger Access Variables in Pipeline?

So, this example is shown for users who are using a Pipeline.
`
node {
properties([
pipelineTriggers([
[$class: 'GenericTrigger',
genericVariables: [
[expressionType: 'JSONPath', key: 'variable1', value: 'expression1'],
[expressionType: 'JSONPath', key: 'variable2', value: 'expression2']
],
regexpFilterText: '',
regexpFilterExpression: ''
]
])
])

stage("build") {
sh '''
echo Build
'''
}
}
`

But how can we access variable1, and variable2 from within stage build? It may be a good idea to make the example echo similar to what the Job DSL example had.

Generic Webhook hook stops working on v1.15

After updating to v1.15, our webhook that used to work no longer works. Jenkins logs spits out:

INFO: Did not find any jobs to trigger! The user invoking /generic-webhook-trigger/invoke must have read permission to any jobs that should be triggered.

The webhook looks like this:

https://jenkins_user:[email protected]/generic-webhook-trigger/invoke

After rolling back to v1.14, everything works again.

regexpFilterText & regexpFilterExpression not working?

I have a multibranch project and wanted to create an filter that listens to the github repository name and the branch that is pushed to.
But with the following pipeline - even with some other excape sequences (or without) I can not get it working :(

    properties([
        pipelineTriggers([
            [$class: 'GenericTrigger', 
                genericVariables: [
                    [expressionType: 'JSONPath', key: 'reference', value: '$.ref'],
                    [expressionType: 'JSONPath', key: 'before', value: '$.before'],
                    [expressionType: 'JSONPath', key: 'repository', value: '$.repository.full_name']
                ],
                genericRequestVariables: [
                    [key: 'requestWithNumber', regexpFilter: '[^0-9]'],
                    [key: 'requestWithString', regexpFilter: '']
                ],
                genericHeaderVariables: [
                    [key: 'headerWithNumber', regexpFilter: '[^0-9]'],
                    [key: 'headerWithString', regexpFilter: '']
                ],
                regexpFilterText: '$repository/$reference',
                regexpFilterExpression: 'myGroup\\/myRepo\\/refs\\/heads\\/master'
            ]
        ])
    ])

Would be great if this point would be explained in the documentation :)

Add defaultValue attribute to GenericVariables

Hi, thanks for your work with the plugin, it is great!

I'd like to suggest adding the defaultValue attribute to GenericVariables, as the example below:

genericVariables: [ [expressionType: 'JSONPath', key: 'VAR', value: '$.node', defaultValue: 'some_value']

Doesn't work with Pipelines

It seems this plugin is not working with pipelines.

In the Jenkinsfile I've this properties are configured:
properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')), pipelineTriggers([[$class: 'GenericTrigger', regexpFilterExpression: '', regexpFilterText: '']])])

I've just scanned your source-code and I think a function for PipelineTriggers is missing.

Want to get the entire payload (cause.getPostContent() )

I am trying to use this awesome plugin to get the non modified received body. so that I can send the paylaod as it is to a kafka using curl.
using Post content parameters - variale PAY_LOAD giving the modified information.

How can I access the actual payload which gets printed under GenericWebhookEnvironmentContributor
Received: ?

Please help!

Passing ?token=TOKENHERE doesnt work

For some reason when i try to pass a token param to use the token auth it is being ignored and i get the following error:

{"status":"ok","data":{"triggerResults":{"ANY":"Did not find any jobs to trigger! The user invoking /generic-webhook-trigger/invoke must have read permission to any jobs that should be triggered. You may try adding http://user:passw@url... or configuring and passing an authentication token like ...trigger/invoke?token=TOKENHERE"}}}

Can anyone please advise on whether they experience the same or its just my jenkins instance?

Build trigger fails while using token authorization

When I'm trying to invoke an endpoint without user:token, just by using ?token=xxxx the build is triggered but getting the error:

{
    "status": "ok",
    "data": {
        "triggerResults": {
            "jenkins-test": "Exception occurred, full stack trace in Jenkins server log. Thrown in: org.jenkinsci.plugins.gwt.GenericTriggerResults:21"
        }
    }
}

P.S. If I provide a wrong token the given response has right error message.

1.28 NPE

Updating from 1.27 to 1.28 when the webhooks are accessed they throw a NullPointerException:

java.lang.NullPointerException
	at jenkins.plugins.slack.webhook.WebhookEndpoint.getUrlName(WebhookEndpoint.java:51)
	at jenkins.model.Jenkins.getUnprotectedRootActions(Jenkins.java:4674)
	at jenkins.model.Jenkins.isSubjectToMandatoryReadPermissionCheck(Jenkins.java:4646)
	at jenkins.model.Jenkins.getTarget(Jenkins.java:4624)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:674)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:845)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
	at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
	at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:157)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:105)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
	at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
	at jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
	at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
	at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:135)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
	at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
	at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:93)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
	at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
	at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
	at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:90)
	at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:82)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:564)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
	at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199)
	at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Declarative Pipeline support

It would be nice to have a chance to use this plugin with declarative pipeline under trigger sections.
In my case we have all pipelines written in declarative way except one using generic trigger.

Conditional trigger

Trigger only if variable resolves to a specific value.

Usa case is to trigger only when object_kind is merge_request.

{"object_kind":"merge_request","user":{"name":"Administrator","username":"root","avatar_url":"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon"},"project":{"name":"violations-test","description":"","web_url":"http://a3dffa263a40/root/violations-test","avatar_url":null,"git_ssh_url":"git@a3dffa263a40:root/violations-test.git","git_http_url":"http://a3dffa263a40/root/violations-test.git","namespace":"root","visibility_level":20,"path_with_namespace":"root/violations-test","default_branch":"feature/addingcrap","homepage":"http://a3dffa263a40/root/violations-test","url":"git@a3dffa263a40:root/violations-test.git","ssh_url":"git@a3dffa263a40:root/violations-test.git","http_url":"http://a3dffa263a40/root/violations-test.git"},"object_attributes":{"id":1,"target_branch":"master","source_branch":"feature/addingcrap","source_project_id":1,"author_id":1,"assignee_id":null,"title":"some crap","created_at":"2017-02-20 19:54:06 UTC","updated_at":"2017-03-12 21:33:23 UTC","milestone_id":null,"state":"opened","merge_status":"unchecked","target_project_id":1,"iid":1,"description":"","position":0,"locked_at":null,"updated_by_id":null,"merge_error":null,"merge_params":{"force_remove_source_branch":null},"merge_when_build_succeeds":false,"merge_user_id":null,"merge_commit_sha":null,"deleted_at":null,"in_progress_merge_commit_sha":null,"lock_version":null,"time_estimate":0,"source":{"name":"violations-test","description":"","web_url":"http://a3dffa263a40/root/violations-test","avatar_url":null,"git_ssh_url":"git@a3dffa263a40:root/violations-test.git","git_http_url":"http://a3dffa263a40/root/violations-test.git","namespace":"root","visibility_level":20,"path_with_namespace":"root/violations-test","default_branch":"feature/addingcrap","homepage":"http://a3dffa263a40/root/violations-test","url":"git@a3dffa263a40:root/violations-test.git","ssh_url":"git@a3dffa263a40:root/violations-test.git","http_url":"http://a3dffa263a40/root/violations-test.git"},"target":{"name":"violations-test","description":"","web_url":"http://a3dffa263a40/root/violations-test","avatar_url":null,"git_ssh_url":"git@a3dffa263a40:root/violations-test.git","git_http_url":"http://a3dffa263a40/root/violations-test.git","namespace":"root","visibility_level":20,"path_with_namespace":"root/violations-test","default_branch":"feature/addingcrap","homepage":"http://a3dffa263a40/root/violations-test","url":"git@a3dffa263a40:root/violations-test.git","ssh_url":"git@a3dffa263a40:root/violations-test.git","http_url":"http://a3dffa263a40/root/violations-test.git"},"last_commit":{"id":"a7b8f8669a8cda51c3fc64ac20e3c32f8442a8c3","message":"asd\n","timestamp":"2017-03-12T22:33:19+01:00","url":"http://a3dffa263a40/root/violations-test/commit/a7b8f8669a8cda51c3fc64ac20e3c32f8442a8c3","author":{"name":"Tomas Bjerre","email":"[email protected]"}},"work_in_progress":false,"url":"http://a3dffa263a40/root/violations-test/merge_requests/1","action":"update","oldrev":"a17426aa8eacda851e3855f183ee244f5fd3a5c1"},"repository":{"name":"violations-test","url":"git@a3dffa263a40:root/violations-test.git","description":"","homepage":"http://a3dffa263a40/root/violations-test"}}

After auth still can't trigger things

Hi,
I've a private bitbucket repo and want to connect via SSH key. Standard Bitbucket plugin is useless since it only provides auth by password (I don't want to create new Jenkins user at Bb and don't want to use my own credentials).

In both multibranch pipelines I've setted this plugin in same way:
zrzut ekranu z 2017-05-09 13-58-22
and use webook: http://username:[email protected]:8080/generic-webhook-trigger/invoke

but still have

May 09, 2017 1:59:35 PM org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver doInvoke
INFO: Did not find any jobs to trigger! The user invoking /generic-webhook-trigger/invoke must have read permission to any jobs that should be triggered.

Jenkins is setted to "everyone can do everything" and disallowed is to read by everyone; Jenkins SSH key is added to project, not Bb account

Tried via Bb webhooks, Postman and cUrl, still same response (no triggered tasks):

{
	"status": "ok",
	"data": {
		"triggerResults": {}
	}
}

XmlFlattener doesn't work with Attribute nodes

The XMLFlattener only allows access to Element nodes and not Attribute nodes.

e.g.
Element nodes successfully work with an XPATH of /element
<element>value</element>

Attribute nodes do no work with an XPATH of /attribute[@name='key']/@value
<attribute name='key' value='value' />

I've tried a fix for this by modifying isXmlLeafNode() to check for either ELEMENT_NODE or ATTRIBUTE_NODE which resolved the problem I had.

return node != null && (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.ATTRIBUTE_NODE) && node.getChildNodes().getLength() == 1 && node.getFirstChild().getNodeType() == Node.TEXT_NODE;

How to avoid triggering unrelated jobs?

I have a single Jenkins instance hosting multiple jobs, which build different repos. I noticed a post message from one repo would trigger unrelated jobs. I understand that there is only one webhook url, but shouldn't Jenkins do some internal matching to trigger only the job that is relevant? For example, with the GitHub Plugin, I didn't see unrelated job being triggered. But that is not the case with the Generic Webhook Trigger Plugin.

Is it by design, or am I missing something?

If this is how it was designed, can we have multiple "Optional Filters", or can we have "positive" "Parameter Filter"? (I understand we can extract the source repo as a parameter, but the regex can only remove the match, not retain the match; I could use the "Optional Fitler" for matching the repo, but I am already using it to match a tag).

This is an awesome plugin. Thank you for the great work!

Cannot auth from Bitbucket

I'm using Generic Webhook Trigger Plugin 1.8. I'm not granting read access to anonymous user in Jenkins Global Security Matrix-based security. I have only one job with "Generic Webhook Trigger" enabled.

When I tested with curl http://user:[email protected]:8080/generic-webhook-trigger/invoke, it triggered the job. But when I tested from Bitbucket using the same url in Post Webhook, it didn't, and I got "Did not find any jobs to trigger!" in the log.

Relatedly, I enabled "Trigger builds remotely" in my Jenkins job, set a simple token, and added that to Bitbucket (.../invoke?token=mytoken), but that didn't help the issue above. Also, when tested with curl, any token value (or none at all) would trigger the job.

No such property

Migrating to an AWS Jenkins I ran into the following problem:

node {
    properties([
        pipelineTriggers([
            [$class: 'GenericTrigger', 
                genericVariables: [
                    [expressionType: 'JSONPath', key: 'reference', value: '$.ref'],
                    [expressionType: 'JSONPath', key: 'before', value: '$.before'],
                    [expressionType: 'JSONPath', key: 'after', value: '$.after'],
                    [expressionType: 'JSONPath', key: 'repository', value: '$.repository.full_name']
                ],
                genericRequestVariables: [],
                genericHeaderVariables: []
            ]
        ])
    ])
    
    stage("run") 
        echo $reference
    }
}

on triggering the webhook the build fails with No such property: $reference for class: groovy.lang.Binding:

Generic Cause
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/_autobuild
[Pipeline] {
[Pipeline] properties
GenericWebhookEnvironmentContributor Received:




Contributing variables:



[Pipeline] stage
GenericWebhookEnvironmentContributor Received:




Contributing variables:



[Pipeline] { (run)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: $reference for class: groovy.lang.Binding
	at groovy.lang.Binding.getVariable(Binding.java:63)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:242)
	at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:282)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:286)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:262)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:262)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
	at WorkflowScript.run(WorkflowScript:27)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
	at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
	at sun.reflect.GeneratedMethodAccessor517.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

Jenkins ver. 2.73.2
Generic Webhook Trigger PluginTrigger 1.20

When building using a token, the cause parameter has no effect

When you build using a token (i.e. JENKINS_URL/job/my_job/build?token=sometoken&cause=The+Cause) the build lists the cause as "Started by remote host 127.0.0.1 with note: The Cause"

When you trigger a build via a webhook (i.e. JENKINS_URL/generic-webhook-trigger/invoke?token=sometoken&cause=The+Cause) the cause is always "Generic Cause"

Is it possible to pass the cause parameter through so it can be shown with the build as the reason the build was triggered?

Thank you

Unable to resolve variable

I'm trying to get the repository name from a github webhook POST. The payload looks like this (truncated for clarity):

{
  "repository": {
    "name": "foo"
  }
}

And I've tested at https://jsonpath.curiousconcept.com/ that $.repository.name correctly parses for the respository name.

However, the jenkins job is continually failing to add the variable. When I look at the logs I see the following message:

Dec 20, 2017 1:06:01 PM INFO org.jenkinsci.plugins.gwt.resolvers.PostContentParameterResolver resolve
Unable to resolve repository_name

My configuration looks correct to me:

image

I am running Jenkins 2.89.2
And generic-webhook-trigger-plugin 1.20

Retrieve Jenkins queue status [improvements]

Since 1.24 data.triggerResults returns queue info - and it's great, but if my Jenkins job is already in progress it would be cool also get queue status pending, started otherwise.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.