jenkinsci / generic-webhook-trigger-plugin

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.
https://plugins.jenkins.io/generic-webhook-trigger
410 stars 160 forks source link

The JSON response is not shown in Jenkins log, even if it is configured to be shown #292

Closed GitHubaajat closed 8 months ago

GitHubaajat commented 8 months ago

Problem

Configuration info

tomasbjerre commented 8 months ago

Can you provide the output of this script (you can run it from Jenkins > Manage Jenkins > Script Console):

println("Jenkins: ${Jenkins.instance.getVersion()}")
println("OS: ${System.getProperty('os.name')} - ${System.getProperty('os.version')}")
println("Java: ${System.getProperty('java.version')} - ${System.getProperty('java.vm.vendor')} (${System.getProperty('java.vm.name')})")
println "---"

Jenkins.instance.pluginManager.plugins
  .collect()
  .sort { it.getShortName() }
  .each {
    plugin -> println("${plugin.getShortName()}:${plugin.getVersion()}")
  }
return
GitHubaajat commented 8 months ago

Plugin is invoked from:

These configurations no longer works as expected:

Before the plugin update, the JSON payload was printed to the Jenkins job's build log. That no longer happens.

Environment: Jenkins: 2.426.3 OS: Linux - 4.14.219-161.340.amzn2.x86_64 Java: 11.0.11 - AdoptOpenJDK (OpenJDK 64-Bit Server VM)

Office-365-Connector:4.20.2 ace-editor:1.1 active-directory:2.34 analysis-core:1.96 android-emulator:592.vb_b_6d427f1923 ansible:285.v2f044b_eb_7a_3e ansicolor:1.0.4 ant:497.v94e7d9fffa_b_9 antisamy-markup-formatter:162.v0e6ec0fcfcf6 apache-httpcomponents-client-4-api:4.5.14-208.v438351942757 artifactory:4.0.3 authentication-tokens:1.53.v1c90fd9191ab aws-credentials:218.v1be9466ec5da aws-java-sdk:1.12.633-430.vf9a_e567a_244f aws-java-sdk-cloudformation:1.12.633-430.vf9a_e567a_244f aws-java-sdk-codebuild:1.12.633-430.vf9a_e567a_244f aws-java-sdk-ec2:1.12.633-430.vf9a_e567a_244f aws-java-sdk-ecr:1.12.633-430.vf9a_e567a_244f aws-java-sdk-ecs:1.12.633-430.vf9a_e567a_244f aws-java-sdk-efs:1.12.633-430.vf9a_e567a_244f aws-java-sdk-elasticbeanstalk:1.12.633-430.vf9a_e567a_244f aws-java-sdk-iam:1.12.633-430.vf9a_e567a_244f aws-java-sdk-kinesis:1.12.633-430.vf9a_e567a_244f aws-java-sdk-logs:1.12.633-430.vf9a_e567a_244f aws-java-sdk-minimal:1.12.633-430.vf9a_e567a_244f aws-java-sdk-secretsmanager:1.12.633-430.vf9a_e567a_244f aws-java-sdk-sns:1.12.633-430.vf9a_e567a_244f aws-java-sdk-sqs:1.12.633-430.vf9a_e567a_244f aws-java-sdk-ssm:1.12.633-430.vf9a_e567a_244f azure-ad:449.v92b_39a_d8e523 azure-sdk:157.v855da_0b_eb_dc2 badge:1.9.1 bitbucket:241.v6d24a_57f9359 bitbucket-pullrequest-builder:1.5.0 blueocean-autofavorite:1.2.5 blueocean-bitbucket-pipeline:1.27.9 blueocean-commons:1.27.9 blueocean-config:1.27.9 blueocean-core-js:1.27.9 blueocean-dashboard:1.27.9 blueocean-display-url:2.4.2 blueocean-events:1.27.9 blueocean-git-pipeline:1.27.9 blueocean-github-pipeline:1.27.9 blueocean-i18n:1.27.9 blueocean-jira:1.27.9 blueocean-jwt:1.27.9 blueocean-personalization:1.27.9 blueocean-pipeline-api-impl:1.27.9 blueocean-pipeline-editor:1.27.9 blueocean-pipeline-scm-api:1.27.9 blueocean-rest:1.27.9 blueocean-rest-impl:1.27.9 blueocean-web:1.27.9 bootstrap4-api:4.6.0-6 bootstrap5-api:5.3.2-3 bouncycastle-api:2.30.1.77-225.v26ea_c9455fd9 branch-api:2.1144.v1425d1c3d5a_7 build-monitor-plugin:1.14-826.vb_a_c11536174d build-name-setter:2.4.0 build-pipeline-plugin:2.0.1 build-timeout:1.32 built-on-column:1.4 caffeine-api:3.1.8-133.v17b_1ff2e0599 checks-api:2.0.2 checkstyle:4.0.0 cloudbees-bitbucket-branch-source:866.vdea_7dcd3008e cloudbees-folder:6.858.v898218f3609d clover:4.14.1.577.vb_ff5a_f69b37b cobertura:1.17 code-coverage-api:4.99.0 command-launcher:107.v773860566e2e commons-httpclient3-api:3.1-3 commons-lang3-api:3.13.0-62.v7d18e55f51e2 commons-text-api:1.11.0-95.v22a_d30ee5d36 conditional-buildstep:1.4.3 config-file-provider:959.vcff671a4518b confluence-publisher:163.vf906edb_73cce copyartifact:722.v0662a_9b_e22a_c coverage:1.9.0 credentials:1311.vcf0a_900b_37c2 credentials-binding:657.v2b_19db_7d6e6d custom-tools-plugin:0.8 cvs:2.19.1 data-tables-api:1.13.8-2 description-setter:239.vd0a_6b_785f92d display-url-api:2.200.vb_9327d658781 docker-commons:439.va_3cb_0a_6a_fb_29 docker-workflow:572.v950f58993843 durable-task:543.v262f6a_803410 ec2:1648.vf3d852e00486 echarts-api:5.4.3-2 envinject:2.908.v66a_774b_31d93 envinject-api:1.199.v3ce31253ed13 extended-choice-parameter:376.v2e02857547ba external-monitor-job:215.v2e88e894db_f8 favorite:2.208.v91d65b_7792a_c findbugs:5.0.0 font-awesome-api:6.5.1-2 forensics-api:2.3.0 generic-webhook-trigger:1.88.2 git:5.2.1 git-client:4.6.0 git-server:99.va_0826a_b_cdfa_d github:1.37.3.1 github-api:1.318-461.v7a_c09c9fa_d63 github-branch-source:1772.va_69eda_d018d4 gradle:2.9 greenballs:1.15.1 groovy:457.v99900cb_85593 groovy-postbuild:228.vcdb_cf7265066 gson-api:2.10.1-15.v0d99f670e0a_7 handy-uri-templates-2-api:2.1.8-30.v7e777411b_148 htmlpublisher:1.32 instance-identity:185.v303dc7c645f9 ionicons-api:56.v1b_1c8c49374e ivy:2.5 jackson2-api:2.16.1-373.ve709c6871598 jacoco:3.3.5 jakarta-activation-api:2.0.1-3 jakarta-mail-api:2.0.1-3 javadoc:243.vb_b_503b_b_45537 javax-activation-api:1.2.0-6 javax-mail-api:1.6.2-9 jaxb:2.3.9-1 jdk-tool:73.vddf737284550 jenkins-design-language:1.27.9 jenkins-jira-issue-updater:1.18 jenkins-multijob-plugin:623.v03401733c9a_9 jersey2-api:2.41-133.va_03323b_a_1396 jira:3.12 jjwt-api:0.11.5-77.v646c772fddb_0 jnr-posix-api:3.1.18-1 job-dsl:1.87 joda-time-api:2.12.6-21.vca_fd74418fb7 jquery:1.12.4-1 jquery-detached:1.2.1 jquery3-api:3.7.1-1 jsch:0.2.16-86.v42e010d9484b json-path-api:2.9.0-33.v2527142f2e1d junit:1256.v002534a_5f33e ldap:711.vb_d1a_491714dc lockable-resources:1232.v512d6c434ebd mailer:463.vedf8358e006b mapdb-api:1.0.9-28.vf251ce40855d mask-passwords:173.v6a_077a_291eb_5 matrix-auth:3.2.1 matrix-project:822.v01b_8c85d16d2 maven-plugin:3.23 mercurial:1260.vdfb_723cdcc81 mina-sshd-api-common:2.12.0-90.v9f7fb_9fa3d3b mina-sshd-api-core:2.12.0-90.v9f7fb_9fa3d3b momentjs:1.1.1 nant:248.vcc8a_3eec8db_a newrelic-deployment-notifier:1.11 node-iterator-api:55.v3b_77d4032326 nodejs:1.6.1 okhttp-api:4.11.0-157.v6852a_a_fa_ec11 packer:1.5 pam-auth:1.10 parameterized-trigger:787.v665fcf2a830b pipeline-build-step:540.vb_e8849e1a_b_d8 pipeline-graph-analysis:202.va_d268e64deb_3 pipeline-groovy-lib:700.v0e341fa_57d53 pipeline-input-step:477.v339683a_8d55e pipeline-milestone-step:111.v449306f708b_7 pipeline-model-api:2.2175.v76a_fff0a_2618 pipeline-model-declarative-agent:1.1.1 pipeline-model-definition:2.2175.v76a_fff0a_2618 pipeline-model-extensions:2.2175.v76a_fff0a_2618 pipeline-npm:155.ve2e393062d86 pipeline-rest-api:2.34 pipeline-stage-step:305.ve96d0205c1c6 pipeline-stage-tags-metadata:2.2175.v76a_fff0a_2618 pipeline-stage-view:2.34 pipeline-utility-steps:2.16.1 plain-credentials:143.v1b_df8b_d3b_e48 plugin-util-api:3.8.0 popper-api:1.16.1-3 popper2-api:2.11.6-4 port-allocator:1.10 postbuild-task:1.9 preSCMbuildstep:71.v1f2990a_37e27 prism-api:1.29.0-10 project-description-setter:1.2 promoted-builds:945.v597f5c6a_d3fd pubsub-light:1.18 python:1.3 rebuild:330.v645b7df10e2a resource-disposer:0.23 robot:3.5.0 role-strategy:689.v731678c3e0eb_ run-condition:1.7 sbt:81.vb_82499046630 scm-api:683.vb_16722fb_b80b script-security:1313.v7a_6067dc7087 scriptler:348.v5d461e205daa skip-certificate-check:1.1 snakeyaml-api:2.2-111.vc6598e30cc65 sonar:2.17.1 sse-gateway:1.26 ssh-credentials:308.ve4497b_ccd8f4 sshd:3.322.v159e91f6a_550 startup-trigger-plugin:2.9.4 stash-pullrequest-builder:1.17 stashNotifier:1.464.va_9203f84a_417 structs:337.v1b_04ea_4df7c8 subversion:2.17.3 text-finder:1.26 throttle-concurrents:2.14 timestamper:1.26 token-macro:400.v35420b922dcb trilead-api:2.133.vfb_8a_7b_9c5dd1 variant:60.v7290fc0eb_bcd windows-slaves:1.8.1 workflow-aggregator:596.v8c21c963d92d workflow-api:1283.v99c10937efcb workflow-basic-steps:1042.ve7b_140c4a_e0c workflow-cps:3837.v305192405b_c0 workflow-cps-global-lib:612.v55f2f80781ef workflow-durable-task-step:1313.vcb_970b_d2a_fb_3 workflow-job:1385.vb_58b_86ea_fff1 workflow-multibranch:773.vc4fe1378f1d5 workflow-scm-step:415.v434365564324 workflow-step-api:657.v03be8115821b workflow-support:865.v43e78cc44e0d ws-cleanup:0.45 zentimestamp:4.2

tomasbjerre commented 8 months ago

I started a Jenkins instance from this repository, with this script: https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/run.sh

Installed the pipeline plugin.

Created a pipeline like:

properties([
    pipelineTriggers([
        GenericTrigger(
            causeString: 'Generic Cause',
            genericVariables: [
                [defaultValue: '', key: 'name', regexpFilter: '', value: '$.app.name']
            ],
            printContributedVariables: true,
            printPostContent: true, 
            regexpFilterExpression: '', 
            regexpFilterText: '', 
            token: 'mypipeline', 
            tokenCredentialId: ''
        )
    ])
])

node {
    sh """
    name is '$name'
    """
}

Triggered that pipeline with:

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

Got response:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /jenkins/generic-webhook-trigger/invoke?token=mypipeline HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 32
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Tue, 30 Jan 2024 15:55:12 GMT
< X-Content-Type-Options: nosniff
< Stapler-Trace-001: -> evaluate(<hudson.model.Hudson@2207a214> :hudson.model.Hudson,"/generic-webhook-trigger/invoke")
< Stapler-Trace-002: -> evaluate(((StaplerProxy)<hudson.model.Hudson@2207a214>).getTarget(),"/generic-webhook-trigger/invoke")
< Stapler-Trace-003: -> evaluate(<hudson.model.Hudson@2207a214>.getDynamic("generic-webhook-trigger",...),"/invoke")
< Stapler-Trace-004: -> evaluate(<org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver@3f89ab36> :org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver,"/invoke")
< Stapler-Trace-005: -> <org.jenkinsci.plugins.gwt.GenericWebHookRequestReceiver@3f89ab36>.doInvoke(...)
< Content-Type: application/json;charset=utf-8
< Content-Length: 187
< Server: Jetty(10.0.16)
< 
* Connection #0 to host localhost left intact
{"jobs":{"pipe":{"regexpFilterExpression":"","triggered":true,"resolvedVariables":{"name":"some value"},"regexpFilterText":"","id":13,"url":"queue/item/13/"}},"message":"Triggered jobs."}

The pipeline is triggered and logs:

Generic Cause
[Pipeline] Start of Pipeline
 Received:

{ "app":{ "name":"some value" }}

Contributing variables:

    name = some value

[Pipeline] properties
[Pipeline] node
Running on [Jenkins](http://localhost:8080/jenkins/computer/(built-in)/) in /home/bjerre/workspace/generic-webhook-trigger-plugin/work/workspace/pipe
[Pipeline] {
[Pipeline] sh
+ name is some value
/home/bjerre/workspace/generic-webhook-trigger-plugin/work/workspace/pipe@tmp/durable-e2bf08cd/script.sh: 1: name: not found
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

Closing this issue as I cannot reproduce it.

ntfc commented 5 months ago

I thought I was suffering from the same issue, but in the end the problem was the webhook setup in GitHub. Its content type must be application/json instead of application/x-www-form-urlencoded otherwise the JSON path expression won't work (obviously 🤦 😅 )