riboseinc / aws-codecommit-trigger-plugin

Jenkins plugin for triggering jobs with AWS CodeCommit repo updates
https://www.ribose.com
Apache License 2.0
22 stars 29 forks source link

Does not trigger build? #54

Closed ribose-jeffreylau closed 6 years ago

ribose-jeffreylau commented 6 years ago

Hi @phuonghuynh

After creating a new pipeline job, the plugin does not seem to be receiving any events from AWS codecommit (checked via Jenkins's "All Jenkins Log").

Jenkins version: 2.103

Any ideas why? Thanks!

phuonghuynh commented 6 years ago

@ribose-jeffreylau Is the button "Test Access" return "SUCCESS" ?

https://raw.githubusercontent.com/riboseinc/aws-codecommit-trigger-plugin/master/doc/images/global-config.png

ribose-jeffreylau commented 6 years ago

Hi @phuonghuynh , yes, clicking "Test Access" would make the green arrow with the text "Access to SQS successful" appear.

I should clarify that our Jenkins set up has quite a number of jobs, and only some of the jobs (perhaps they're the most recently created ones) don't seem to be receiving any events.

phuonghuynh commented 6 years ago

Can i have some logs ? @ribose-jeffreylau

kwkwan commented 6 years ago

@phuonghuynh

Here is the log

falling back to default instantiation com.ribose.jenkins.plugin.awscodecommittrigger.SQSScmConfig {"type":"ER","url":"https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo","subscribedBranches":""}
net.sf.json.JSONException: JSONObject["type"] is not a JSONObject.
    at net.sf.json.JSONObject.getJSONObject(JSONObject.java:2006)
    at com.ribose.jenkins.plugin.awscodecommittrigger.SQSScmConfig$DescriptorImpl.newInstance(SQSScmConfig.java:89)
    at com.ribose.jenkins.plugin.awscodecommittrigger.SQSScmConfig$DescriptorImpl.newInstance(SQSScmConfig.java:84)
    at hudson.model.Descriptor$NewInstanceBindInterceptor.onConvert(Descriptor.java:669)
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:621)
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:716)
    at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:478)
    at org.kohsuke.stapler.RequestImpl.instantiate(RequestImpl.java:777)
    at org.kohsuke.stapler.RequestImpl.access$200(RequestImpl.java:83)
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:678)
    at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:478)
    at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:474)
    at hudson.model.Descriptor.newInstance(Descriptor.java:592)
phuonghuynh commented 6 years ago

Thanks @kwkwan

kwkwan commented 6 years ago

@phuonghuynh we have discovered that the newer jobs also cannot be triggered even when they are traditional jobs. The event arrives in the SQS queue, the plugin checks the event for the correct job, but the plugin log still says:

Message contains no text
Jun 13, 2018 4:26:51 PM INFO [c.r.j.p.a.SQSTrigger][thread-00009B][job-xxxxxx] 
Any event matched? false. Message: null
Jun 13, 2018 4:26:51 PM WARNING [c.r.j.p.a.m.CodeCommitMessageParser][thread-00009B] 
phuonghuynh commented 6 years ago

Any event matched? false. Message: null - "Message" should print out "Message-id" that extracted from "Message text" but it is "no text". Message contains no text is new to me. Its weird.

@kwkwan Could I have full body of message sent to the SQS? something like

{
  "Type" : "Notification",
  "MessageId" : "84762aab-8872-5a9e-9ce1-793130f3e80b",
  "TopicArn" : "arn:aws:sns:us-west-2:239062223385:testjenkins-topic",
  "Subject" : "UPDATE: AWS CodeCommit us-west-2 push: testjenkins",
  "Message" : "{\"Records\":[{\"awsRegion\":\"us-west-2\",\"codecommit\":{\"references\":[{\"commit\":\"62f545e463481d2c277325d1f92a1f1a8cb497fd\",\"created\":true,\"ref\":\"refs/heads/dev\"}]},\"customData\":\"branchName\",\"eventId\":\"26757c66-89e2-4e97-80b2-b5d0fd059496\",\"eventName\":\"ReferenceChanges\",\"eventPartNumber\":1,\"eventSource\":\"aws:codecommit\",\"eventSourceARN\":\"arn:aws:codecommit:us-west-2:239062223385:testjenkins\",\"eventTime\":\"2018-06-13T06:14:25.429+0000\",\"eventTotalParts\":1,\"eventTriggerConfigId\":\"b0ef2273-d88a-4946-ada5-c4d98f2c8efc\",\"eventTriggerName\":\"AllEvents\",\"eventVersion\":\"1.0\",\"userIdentityARN\":\"arn:aws:iam::239062223385:user/operations/ext-phuong-huynh\"}]}",
  "Timestamp" : "2018-06-13T06:14:25.464Z",
  "SignatureVersion" : "1",
  "Signature" : "uQh+pzDB10Wi1Ol2gK4WGc97gnC99chpqV8nKJlG+Jvy7xOixntNvsaO7JnywwymFZzheh60/vbpTM+wqRcBTnuNnTyY3Ke1/s7NU0vNlB3JpeIiP+BkATbIhnwC08Lh23TfEgnfwpD4ouDnElZ9yEotqjqUHb+8AslEdknTAgWKdQpb3bMT3P+zFLbDTaoXqMshGqDuupPgOoNeFwx9MxFBve9jhUtATmAHuH6HFMuWvb6iWmuy1A52PwPTR6gh0vIUYpSj+STCDv7ZXqqP8tl4wW/EsjhSaSyqaZuPW4HJswHCHKCLCtr9Eoq1Nywzb6iJMqfsHmH1P2LZfMyScg==",
  "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-eaea6120e66ea12e88dcd8bcbddca752.pem",
  "UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:239062223385:testjenkins-topic:8fa0d552-bbaf-4a19-8555-ac4ba3417345"
}
kwkwan commented 6 years ago

@phuonghuynh is there a debug mode to see the messages sent?

phuonghuynh commented 6 years ago

The message can be retrieve by Email subscription in SNS Topic. I am using it to get message text.

screenshot at jun 13 16-25-43
kwkwan commented 6 years ago

The email-json we got is

{
  "Type" : "Notification",
  "MessageId" : "xxxx-xxxx-xxxx-xxxx-xxxx",
  "TopicArn" : "arn:aws:sns:us-east-1:xxxx:codecommit-xxxx-topic",
  "Subject" : "UPDATE: AWS CodeCommit us-east-1 push: xxxx",
  "Message" : "{\"Records\":[{\"awsRegion\":\"us-east-1\",\"codecommit\":{\"references\":[{\"commit\":\"xxxxxxxxxxxxxxxxx\",\"ref\":\"refs/heads/master\"}]},\"customData\":\"\",\"eventId\":\"xxxx-xxxx-xxxx-xxxx-xxxx\",\"eventName\":\"ReferenceChanges\",\"eventPartNumber\":1,\"eventSource\":\"aws:codecommit\",\"eventSourceARN\":\"arn:aws:codecommit:us-east-1:1111111111:xxxx\",\"eventTime\":\"2018-06-14T02:28:43.851+0000\",\"eventTotalParts\":1,\"eventTriggerConfigId\":\"xxxx-xxxx-xxx-xxxx-xxxx\",\"eventTriggerName\":\"notifications\",\"eventVersion\":\"1.0\",\"userIdentityARN\":\"arn:aws:iam::1111111111:user/system/cc-xxx\"}]}",
  "Timestamp" : "2018-06-14T02:28:43.890Z",
  "SignatureVersion" : "1",
  "Signature" : "xxxxxxxxxxxxxx",
  "SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-xxxxxxxxxx.pem",
  "UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:101221321624:codecommit-xxxx-topic:xxxxxx-xxxx-xxxx-xxxx-xxxx"
}

The log related in jenkins is

Message contains no text
Jun 14, 2018 10:28:43 AM INFO [c.r.j.p.a.SQSTrigger][thread-00009B][job-xxx] 
Any event matched? false. Message: null
phuonghuynh commented 6 years ago

Thanks @kwkwan The message just like mine. So this is interesting issue ^ I will fix it soon

ronaldtse commented 6 years ago

Seems that the plugin can't parse the text given? Thanks @phuonghuynh ! 👍

phuonghuynh commented 6 years ago

@kwkwan Could you enable Jenkins Logging to print out debug logs. The logger should be com.ribose.jenkins.plugin.awscodecommittrigger

screen shot 2018-06-14 at 11 33 51 pm

I also added some more debug logs. You can also use it to see more logs.

aws-codecommit-trigger.hpi.zip

kwkwan commented 6 years ago

I have installed the new plugin and enabled the log. The log becomes:

Any event matched? false. Message: xxx-xxx-xxx-xxx-bc0bd3a845a1
Jun 15, 2018 9:58:49 AM CONFIG [c.r.j.p.a.SQSTrigger][thread-00008A][job-xxx] 
[DEBUG] Parse and do match against events, message: {"Records":[{"awsRegion":"us-east-1","codecommit":{"references":[{"commit":"xxx","ref":"refs/heads/master"}]},"customData":"","eventId":"xxx-xxx-xxx-xxx-77f8d597d981","eventName":"ReferenceChanges","eventPartNumber":1,"eventSource":"aws:codecommit","eventSourceARN":"arn:aws:codecommit:us-east-1:xxx:xxx","eventTime":"2018-06-15T01:58:49.875+0000","eventTotalParts":1,"eventTriggerConfigId":"292b33ed-aa9a-48c5-b106-c22bb8b0a102","eventTriggerName":"notifications","eventVersion":"1.0","userIdentityARN":"arn:aws:iam::xxx:user/system/cc-xxx"}]}
Jun 15, 2018 9:58:49 AM INFO [c.r.j.p.a.m.CodeCommitMessageParser][thread-00008A] 
Retrieved message-id: xxx-xxx-xxx-xxx-bc0bd3a845a1
Jun 15, 2018 9:58:49 AM CONFIG [c.r.j.p.a.m.CodeCommitMessageParser][thread-00008A] 
[DEBUG] Parse Message:
{MessageId: xxx-xxx-xxx-xxx-bc0bd3a845a1,ReceiptHandle: AQEBZsZReEYZl1jlPu97cigbdSiv9uJHUsRxV4yTEx276aOGiUcOpUHIomcJswinG/L8PHRMPqSkA1XVabvjf6DeqqLpmW7QmOKmLVpwDcWFKoPKVUBcTskgQV29IQfHLAnQm101/MXKBs4c7N/QExAv+tQga/h0Yy7BiIUg97SsNDXKv+wNN48oRzqjnsZqcXn5sF8PA+vBjsmV5yrTOq2sgi95e+w5aAwbX+td/I45fjG161Se77fmFMrN1XLSYF50qb4SuwzDowBKy3GCAyKTQlcBK0VJxYs2JnJIW7DrBx2GZeqR9IWsPD9K+DWtYqcyDYUVjnyRBUvVkHfjYWG0fDHRY70xcAsjB6LC7dbzoPDfKND1XUNdJ1918S/O4DmuNEBLt39J8nGccVUV1kFTzA==,MD5OfBody: 1f283a4b923daaa5abc7aafb8eeeb0be,Body: {"Records":[{"awsRegion":"us-east-1","codecommit":{"references":[{"commit":"xxx","ref":"refs/heads/master"}]},"customData":"","eventId":"xxx-xxx-xxx-xxx-77f8d597d981","eventName":"ReferenceChanges","eventPartNumber":1,"eventSource":"aws:codecommit","eventSourceARN":"arn:aws:codecommit:us-east-1:xxx:xxx","eventTime":"2018-06-15T01:58:49.875+0000","eventTotalParts":1,"eventTriggerConfigId":"292b33ed-aa9a-48c5-b106-c22bb8b0a102","eventTriggerName":"notifications","eventVersion":"1.0","userIdentityARN":"arn:aws:iam::xxx:user/system/cc-xxx"}]},Attributes: {},MessageAttributes: {}}
Jun 15, 2018 9:58:49 AM CONFIG [c.r.j.p.a.m.CodeCommitMessageParser][thread-00008A] 
[DEBUG] Retrieved message-body: {"Records":[{"awsRegion":"us-east-1","codecommit":{"references":[{"commit":"xxx","ref":"refs/heads/master"}]},"customData":"","eventId":"xxx-xxx-xxx-xxx-77f8d597d981","eventName":"ReferenceChanges","eventPartNumber":1,"eventSource":"aws:codecommit","eventSourceARN":"arn:aws:codecommit:us-east-1:xxx:xxx","eventTime":"2018-06-15T01:58:49.875+0000","eventTotalParts":1,"eventTriggerConfigId":"292b33ed-aa9a-48c5-b106-c22bb8b0a102","eventTriggerName":"notifications","eventVersion":"1.0","userIdentityARN":"arn:aws:iam::xxx:user/system/cc-xxx"}]}
Jun 15, 2018 9:58:49 AM WARNING [c.r.j.p.a.m.CodeCommitMessageParser][thread-00008A] 
Message contains no text
Jun 15, 2018 9:58:49 AM CONFIG [c.r.j.p.a.m.AndEventTriggerMatcher][thread-00008A] 
[DEBUG] Test if any event not match using c.r.j.p.a.m.i.ScmJobEventTriggerMatcher
Jun 15, 2018 9:58:49 AM CONFIG [c.r.j.p.a.m.i.ScmJobEventTriggerMatcher][thread-00008A][job-xxx] 
[DEBUG] Events size: 0, SCMs size: 1
Jun 15, 2018 9:58:49 AM CONFIG [c.r.j.p.a.m.i.ScmJobEventTriggerMatcher][thread-00008A][job-xxx] 
[DEBUG] No event matched
Jun 15, 2018 9:58:49 AM CONFIG [c.r.j.p.a.m.EventTriggerMatcherImpl][thread-00008A][job-xxx] 
[DEBUG] Finally, events match status is false
phuonghuynh commented 6 years ago

@kwkwan Thanks for the log. It showing that message-body somehow truncated in your case, i added a try-with-message-body function to parse message-body for the case. Could you give it a try?

aws-codecommit-trigger.hpi.zip

If this build fixed your issue, i will make a new release for the Plugin.

kwkwan commented 6 years ago

The log becomes

Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.SQSTrigger][thread-0000C4][job-xxx] 
[DEBUG] Parse and do match against events, message: {"Records":[{"awsRegion":"us-east-1","codecommit":{"references":[{"commit":"xxx","ref":"refs/heads/master"}]},"customData":"","eventId":"xxx-xxx-xxx-xxx-7a33cd881b08","eventName":"ReferenceChanges","eventPartNumber":1,"eventSource":"aws:codecommit","eventSourceARN":"arn:aws:codecommit:us-east-1:xxx:xxx","eventTime":"2018-06-15T08:51:27.660+0000","eventTotalParts":1,"eventTriggerConfigId":"xxx-xxx-xxx-xxx-c22bb8b0a102","eventTriggerName":"notifications","eventVersion":"1.0","userIdentityARN":"arn:aws:iam::xxx:user/system/cc-xxx"}]}
Jun 15, 2018 4:51:27 PM INFO [c.r.j.p.a.m.CodeCommitMessageParser][thread-0000C4] 
Retrieved message-id: xxx-xxx-xxx-xxx-bd847f91b173
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.CodeCommitMessageParser][thread-0000C4] 
[DEBUG] Parse Message:
{MessageId: xxx-xxx-xxx-xxx-bd847f91b173,ReceiptHandle: AQEBJDYXzD/ukqF1c75eF3CoWmWtxpyz2uwXHQKiF+iIZY6JBScAeMxY7Nm5rMPAaGZRLmp3JOjZnAjnviCdNE7kMcbmR5tm1SSQQwvX0wdVlRc1TiTDFSq6fYnv4uPbxZg7kV7tuRjtGsq3Yi+kvGSDpDlmr2X/bqby5cC2zojon71roQYckKUu7KIYfxe/vFdc66JT59Rtgn2QVg9AbxnuW+lTJ6qPhvqP8pv59c5ujbjOvPx+4Xl/mlWNvl8Y1icE6XPI5f/mKge7BaPhjN8EHPmlWRHRVmi764oDST9+F4XkLtLV9W2iC35rRDPTj+HNdLCW91w7t6x/cjop2DLyzQ8wgfdm5ufvKSPxOmwV8UKvowCePut6OG/EVhRw1TIntv/K0XPasmpDoxaNPygCOQ==,MD5OfBody: b54b392d5e377a4a9b68fcc2cdac66ae,Body: {"Records":[{"awsRegion":"us-east-1","codecommit":{"references":[{"commit":"xxx","ref":"refs/heads/master"}]},"customData":"","eventId":"xxx-xxx-xxx-xxx-7a33cd881b08","eventName":"ReferenceChanges","eventPartNumber":1,"eventSource":"aws:codecommit","eventSourceARN":"arn:aws:codecommit:us-east-1:xxx:xxx","eventTime":"2018-06-15T08:51:27.660+0000","eventTotalParts":1,"eventTriggerConfigId":"xxx-xxx-xxx-xxx-c22bb8b0a102","eventTriggerName":"notifications","eventVersion":"1.0","userIdentityARN":"arn:aws:iam::xxx:user/system/cc-xxx"}]},Attributes: {},MessageAttributes: {}}
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.CodeCommitMessageParser][thread-0000C4] 
[DEBUG] Retrieved message-body: {"Records":[{"awsRegion":"us-east-1","codecommit":{"references":[{"commit":"xxx","ref":"refs/heads/master"}]},"customData":"","eventId":"xxx-xxx-xxx-xxx-7a33cd881b08","eventName":"ReferenceChanges","eventPartNumber":1,"eventSource":"aws:codecommit","eventSourceARN":"arn:aws:codecommit:us-east-1:xxx:xxx","eventTime":"2018-06-15T08:51:27.660+0000","eventTotalParts":1,"eventTriggerConfigId":"xxx-xxx-xxx-xxx-c22bb8b0a102","eventTriggerName":"notifications","eventVersion":"1.0","userIdentityARN":"arn:aws:iam::xxx:user/system/cc-xxx"}]}
Jun 15, 2018 4:51:27 PM WARNING [c.r.j.p.a.m.CodeCommitMessageParser][thread-0000C4] 
Message contains no text => Try to parse message-body to records
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.AndEventTriggerMatcher][thread-0000C4] 
[DEBUG] Test if any event not match using c.r.j.p.a.m.i.ScmJobEventTriggerMatcher
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.i.ScmJobEventTriggerMatcher][thread-0000C4][job-xxx] 
[DEBUG] Events size: 1, SCMs size: 1
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.i.ScmJobEventTriggerMatcher][thread-0000C4] 
[DEBUG] Matching event com.ribose.jenkins.plugin.awscodecommittrigger.model.entities.codecommit.CodeCommitEvent@3fc5d07e with SCM git https://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxx
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.i.ScmJobEventTriggerMatcher][thread-0000C4] 
[DEBUG] Git plugin found: true
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.e.c.CodeCommitEvent][thread-0000C4] 
[DEBUG] Event arn:aws:codecommit:us-east-1:xxx:xxx not match path /v1/repos/xxx
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.i.ScmJobEventTriggerMatcher][thread-0000C4] 
[DEBUG] Found no event matched config: 
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.i.ScmJobEventTriggerMatcher][thread-0000C4] 
[DEBUG] Multiple-SCMs plugin found: true
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.i.ScmJobEventTriggerMatcher][thread-0000C4][job-xxx] 
[DEBUG] No event matched
Jun 15, 2018 4:51:27 PM CONFIG [c.r.j.p.a.m.EventTriggerMatcherImpl][thread-0000C4][job-xxx] 
[DEBUG] Finally, events match status is false
Jun 15, 2018 4:51:27 PM INFO [c.r.j.p.a.SQSTrigger][thread-0000C4][job-xxx] 
phuonghuynh commented 6 years ago

[DEBUG] Event arn:aws:codecommit:us-east-1:xxx:xxx not match path /v1/repos/xxx

The matcher failed at Path Matching, could you confirm that the eventSourceARN end withs "repo-name" ?

My case is

ronaldtse commented 6 years ago

(Yes, the eventSourceArn ends with "repo-name").

Wow, I don't know what happened, but it's working now?

Message contains no text => Try to parse message-body to records
Jun 16, 2018 2:54:51 AM INFO [c.r.j.p.a.SQSTrigger][thread-0000C4][job-test-xxxxx] 
Any event matched? true. Message: c270f2fc-3189-4b94-ba62-214d17826b1e
Jun 16, 2018 2:54:51 AM INFO [c.r.j.p.a.m.CodeCommitMessageParser][thread-0000C4] 
phuonghuynh commented 6 years ago

Interesting ^ So, i will make new release now

kwkwan commented 6 years ago

@phuonghuynh When will the jenkins registry be updated? Please let me know. Thanks.

phuonghuynh commented 6 years ago

@kwkwan v2.0.5 has been released https://updates.jenkins.io/current/update-center.actual.json

kwkwan commented 6 years ago

@phuonghuynh Thanks!

vweng commented 4 years ago

I think I had same issue and it bogs down to the trailing slash of the repo URL. Basically Jenkins seems to automatically append a trailing slash to it when it's set by a pipeline script. To fix, I had to change the isMatch() method in com.ribose.jenkins.plugin.awscodecommittrigger.model.entities.codecommit.CodeCommitEvent class to the following:

public boolean isMatch(final URIish uri) { if (uri == null) { return false; } if (!StringUtils.equals(this.host, uri.getHost())) { log.debug("Event %s not match host %s", this.getArn(), uri.getHost()); return false; }

    // ignore the difference of the last slash
    String p1 = this.path.endsWith("/")?this.path:this.path+"/";
    String p2 = uri.getPath().endsWith("/")?uri.getPath():uri.getPath()+"/";
    if (!StringUtils.equals(p1, p2)) {
        log.debug("Event %s not match path %s", this.getArn(), uri.getPath());
        return false;
    }

    log.debug("Event %s match uri %s", this.getArn(), uri);
    return true;
}

`