I have written an API method to create a Bitbucket webhook:
def call (){
script {
CRUMB = "https://api.bitbucket.org/2.0/repositories/$NAMESPACE/$BB_REPO/hooks"
DATA = "'{\n \"description\": \"Webhook Jenkins\",\n \"url\": \"$URL\",\n \"active\": true,\n \"verify\": false,\n \"events\": [\n \"$TRIGGER_EVENTS\"\n ]\n}'"
CONTENT = "\"Content-Type: application/json\""
withCredentials([usernamePassword(credentialsId: 'bb_management', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
final String response = sh(script: "curl --request POST -v -u $USERNAME:$PASSWORD -H $CONTENT -d $DATA $CRUMB ")
}
}
}
However, the URL variable:
\"url\": \"$URL\",\n
Is not working, and I've received this error when a Jenkins job was triggered.
{"type": "error", "error": {"fields": {"url": ["The specified URL is invalid."]}, "message": "Bad request"}}
Could it be a syntax error, how would I resolve this error please?