Closed yuchengren closed 7 months ago
Can you supply complete pipeline
, request
with curl command and response
?
Can you supply complete
pipeline
,request
with curl command andresponse
? ` pipeline { agent any
environment { SCRIPT_PROJECT_ROOT = "/Users/macuser/PycharmProjects/smartscripts" }
triggers { GenericTrigger( genericVariables: [ [key: 'BODY', value: '$', expressionType: 'JSONPath', //Optional, defaults to JSONPath regexpFilter: '', //Optional, defaults to empty string defaultValue: '' //Optional, defaults to empty string ], ], causeString: 'Generic Cause', token: 'gitlab', printContributedVariables: true, printPostContent: true, silentResponse: true, ) }
stages { stage('action') { steps { sh "export PYTHONPATH=${SCRIPT_PROJECT_ROOT} && python3 -u ${SCRIPT_PROJECT_ROOT}/android/jenkins/webhook/webhook-gitlab.py \ --data $BODY \ " } } } } `
the jenkins execute log: `
$BODY output is not raw json,but a JSONPATH string.
I am missing the curl-command. Also the log, ans specifically the contributed variables.
I am missing the curl-command. Also the log, ans specifically the contributed variables.
It it just trigger by gitlab webhook, the URL is
http://JENKINS_URL/generic-webhook-trigger/invoke?token=gitlab
,
I want to do something after push, and I need to raw json body
This is impossible to investigate if you do not supply something that I can reproduce.
the gitlab we
This is impossible to investigate if you do not supply something that I can reproduce.
sorry, I do not understand, Has any else Do you need? The webhook is not a curl-command, it is just trigger by gitlab push event。the gitlab push event, webhook body sample is on docs: https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html
more jenkins log: Generic Cause GenericWebhookEnvironmentContributor Received:
{"object_kind":"push","event_name":"push",...}
Contributing variables:
BODY = {"object_kind":"push","event_name":"push",..}
python3 -u /Users/macuser/PycharmProjects/smartscripts/android/jenkins/webhook/webhook-gitlab.py --data object_kind:push event_name:push...
=== the BODY variables in log is Json,but in pipeline shell command $BODY is not json, but JSONPATH format
So you are saying that if you do:
sh """
echo "BODY: " + BODY
"""
You do not get BODY: {"object_kind":"push","event_name":"push",..}
?
What exactly do you get?
- object_kind:push event_name:push ...
Yes ! , sh "export PYTHONPATH=${SCRIPT_PROJECT_ROOT} && python3 -u ${SCRIPT_PROJECT_ROOT}/android/jenkins/webhook/webhook-gitlab.py --data $BODY " the $BODY is not json, but JSONTPATH format string -> object_kind:push event_name:push ...
If you print the variable, like I said, you will see that it is the raw json.
You problem is probably is how you are using the value. See https://stackoverflow.com/a/38385227/2477084
If you print the variable, like I said, you will see that it is the raw json.
You problem is probably is how you are using the value. See https://stackoverflow.com/a/38385227/2477084
you are right! the BODY is a raw json. thanks very much . The problem is that, shell command json param is need to wrap by ''
Hello, my pipeline like this
genericVariables: [ [key: 'BODY', value: '$', expressionType: 'JSONPath', //Optional, defaults to JSONPath regexpFilter: '', //Optional, defaults to empty string defaultValue: '' //Optional, defaults to empty string ], ],
when I user $BODY in shell script, it is not a raw json, but a JSONPATH format string 。 How can I get the raw json body, sample: gitlab payload json body