#gocd

/

      • butts_butts joined the channel
      • butts_butts
        Hi all. I'm trying to write a Go CD SCM plugin; currently I exported a simple plugin, and it appears in the Admin > Plugins section. However it doesn't appear in the list when I try to choose a source for a material.
      • I should say, I'm using Kotlin instead of Java, not sure if that would be a problem.
      • I'm handling the "scm-configuration" request and sending back basically the same stuff I found in the SCM example, that I found through the Go CD docs.
      • Still, it doesn't appear in that list. Any ideas?
      • hump joined the channel
      • hump
        Anyone here?
      • hump has quit
      • moritz has quit
      • arvindsv
        butts_butts: Did you see any error in the plugins page? Any logs in the log dir?
      • butts_butts
        arvindsv: there were no errors in the plugins page, no. I'll check the logs now.
      • arvindsv: so there are a bunch of ERROR logs, related to plugins, with messages like "Failed to fetch Plugin Settings metadata for plugin : cd.go.authentication.passwordfile java.lang.RuntimeException: Interaction with plugin with id 'cd.go.authentication.passwordfile' implementing 'authorization' extension failed while requesting for 'go.plugin-settings.get-configuration'. Reason: [The plugin sent a response that could not be understood by Go. Plugin
      • But none that mention my plugin.
      • arvindsv
        Ok. Where did you check that it does not show up? I wonder if this bug could be affecting you too: https://github.com/gocd/gocd/issues/2947
      • Maybe check while editing a pipeline to add a material?
      • butts_butts
        Ah. Actually I was always looking in the list via editing an existing pipeline. I just tried adding a new pipeline to see if it worked that way, but it also doesn't show up there.
      • So, both places.
      • arvindsv
        Is the code available somewhere? Or is it going to be private?
      • Also, maybe starting from another SCM plugin's code might help. Like this one: https://github.com/gocd/go-plugins/blob/master/...
      • butts_butts
        Private I'm afraid.
      • Yeah, this is the example I've been working from.
      • I was wondering, does the plugin need to have correct responses for *all* of the messages listed on this page: https://developer.gocd.org/16.3.0/writing_go_pl...
      • Or if I only support, for example, the "scm-configuration" request with a correct response, is that enough for it to appear as a material in Go?
      • And more generally, how can I debug the plugin, is there a way I can make print statements?
      • arvindsv
        Hmm. Usually, the reason it won't show is because it is not recognized as an SCM plugin. Do you respond to this: https://github.com/gocd/go-plugins/blob/2c0cc22...
      • With the argument: "scm"?
      • Yes, once the plugin is loaded and works, you can use log statements wherever you want.
      • The problem, in this case, is that it is not loaded/recognized as an SCM plugin.
      • I think.
      • butts_butts
        Yup, I respond to `pluginIdentifier`
      • arvindsv
        This is part of the infra, which you'll have no control over - from a plugin perspective.
      • You respond with: "scm", ["1.0"]?
      • butts_butts
        Yup.
      • It's Kotlin, but:
      • override fun pluginIdentifier(): GoPluginIdentifier { return GoPluginIdentifier(EXTENSION_NAME, listOf("1.0")) }
      • Where EXTENSION_NAME is:
      • val EXTENSION_NAME = "scm";
      • arvindsv
        Hmm.
      • Ok.
      • In your equivalent of this line: https://github.com/gocd/go-plugins/blob/2c0cc22..., maybe put in a throw or print out something to a file.
      • So that we can see if it's coming there.
      • You could also debug it, in IntelliJ, if you attach to the server process.
      • To your earlier question, usually, you need to respond to all the messages there.
      • But, if you don't, I'd expect something to fail/throw.
      • So, I'm suspecting it is not loaded.
      • It's possible that the JAR is not exported properly from your build and it's not finding it.
      • I suppose you have the annotation: https://github.com/gocd/go-plugins/blob/2c0cc22...
      • That's what it uses to figure out which class to send the message to (and create an instance of).
      • butts_butts
        Yup, I have the @Extension annotation.
      • I think it is getting loaded by Go, because I see it in Admin > Plugins.
      • Also, if I don't implement `pluginIdentifier`, an error shows up in the Admin > Plugins section for my plugin.
      • I'll try throwing in the handle function.
      • - I should mention, I'm primarily a c++ programmer; this is the first time I've dabbled in the Java world
      • Quite possible I'm building the jar incorrectly or something. In IntelliJ IDEA, I'm using build artifact.
      • arvindsv
        :) That's ok. You're doing well so far. This is not your fault. GoCD should be telling you what's going on.
      • butts_butts
        :)
      • arvindsv
        Yeah, throw in the handle function and let's see.
      • butts_butts
        When I setup the build artifact stuff in IDEA, it wouldn't let me choose my the entry point file, unless that file had a main function inside it, so I added an empty one. Not sure if that can cause any issues?
      • arvindsv
        No, that should be ok.
      • butts_butts
        Ok, throwing an IllegalArugumentException in that function; loading now.
      • Interaction with plugin with id 'TestMaterial' implementing 'scm' extension failed while requesting for 'scm-configuration'. Reason: [null]
      • Ok, I guess that's something.
      • It's calling the function.
      • arvindsv
        Ok, that should be happening from around here: https://github.com/gocd/gocd/blob/be1ff52e07d80...
      • Do you now see a message in the logs? "Failed to fetch SCM metadata for plugin ..."
      • In the server los.
      • logs*
      • butts_butts
        Will check
      • Yup!
      • Ok.
      • So it's definitely getting into there.
      • arvindsv
        Ok, good. Can you check the logs to see if you had any messages earlier about this?
      • butts_butts
        Yup
      • Well, if you mean before I put in the exception? This definitely wasn't in the logs then
      • I searched for some keywords that didn't appear then, that are there now
      • arvindsv
        I see. And, were you handling the 'scm-view' call too, earlier?
      • The displayValue in the response to 'scm-view' is what is supposed to show up in the dropdown.
      • I guess you have. Otherwise, you'd see the message: "Failed to fetch SCM metadata for plugin"
      • butts_butts
        I was handling "scm-view" earlier, like a few days ago. Then I removed everything except for "scm-configuration" to try and nail down what was failing.
      • So currently no, I'm not handling scm-view. I assumed that scm-view was the Angular view that would show up if you added the material to a pipeline; the UI that you would enter the repository location, etc?
      • arvindsv
        Right. But, the 'displayValue' in that response to scm-view is important. It's needed for the dropdown.
      • butts_butts
        Ah, ok
      • I'll re-activate that then
      • arvindsv
        You can also use the logger like this: https://github.com/gocd/go-plugins/blob/2c0cc22...
      • And it'll log to a plugin-specific log file.
      • Maybe you can log the requests and your responses.
      • I usually just do something like this: https://github.com/gocd-contrib/gocd_auth_plugi...
      • That way, I have a running log of what is going on.
      • butts_butts
        Ah, nice. I'll do that next, maybe I'm returning some garbage JSON.
      • arvindsv
        I don't think so. If the JSON was invalid, you'd still see a message in the logs.
      • I'm now curious what's going on.
      • Tell me when you find out. :)
      • butts_butts
        Will do
      • No doubt it's something small that I've forgotten!
      • I tried to throw inside the function I'm calling for scm-configuration and scm-view (instead of inside handle() )
      • And now I see no errors
      • So it seems they're not called, but the handle() function is called.
      • arvindsv
        Ok. So, you're not dispatching to your functions inside the plugin?
      • butts_butts
        I wonder if this is a problem with the Kotlin when(..) { .. } syntax that I'm using to replace the if-else chain in the Java examples
      • I am doing, but using this when syntax.
      • arvindsv
        Kotlin does compile down to Java.
      • So, I'd be surprised if it fails there.
      • butts_butts
        But perhaps I'm using the syntax incorrectly
      • Will check with a simple if
      • arvindsv
        Possibly.
      • You could also add the default condition (I don't know Kotlin) to see if it's falling through.
      • butts_butts
        As I said this is all new to me, so I (perhaps foolishly!) decided to try Kotlin instead of Java.
      • arvindsv
        when ... else.
      • :)
      • Hey, what's fun about sticking to what we know.
      • I'm sure you can make it work with Kotlin.
      • butts_butts
        Hope so! Kotlin seems like quite a nice language, lots of syntactic sugar.
      • Ok, some progress
      • I'm now getting "Failed to fetch Plugin Settings metadata for plugin"
      • I'm handling only scm-view and scm-configuration, and from looking a bit at the Go source, I guess this error is because I'm not handling one of the other messages.
      • Ok, so the problem was
      • In my `handle` function, I was returning a response with the not-found code (404), if one of the messages wasn't handled.
      • I did that because Kotlin wouldn't let me return `null`, and the fix for this is adding ? to the return type for the `handle` function, so that I can return null.
      • Now, returning null for unimplemented requests, I get errors in the log.
      • Now I'll test to see if the Kotlin `when` syntax will work.
      • Yup, when syntax works.
      • Now I'll add back the implementations of the other requests... and hopefully....
      • arvindsv
        Ok good!
      • butts_butts
        This "Plugin Settings metadata" error, is that about the response to validate-scm-configuration?
      • arvindsv
        What else does it say?
      • It's about either the config or the view messages.
      • Not about validate.
      • moritz joined the channel
      • butts_butts
        "2017-06-26 17:18:31,543 ERROR [Thread-75] PluginSettingsMetadataLoader:77 - Failed to fetch Plugin Settings metadata for plugin : TestPlugin java.lang.RuntimeException: Interaction with plugin with id 'TestPlugin' implementing 'scm' extension failed while requesting for 'go.plugin-settings.get-configuration'. Reason: [The plugin sent a null response]"
      • It's saying I sent a null response to one of the requests, view or config?
      • arvindsv
        Are you handling the go.plugin-settings.get-configuration message?
      • That's what it is sending.
      • And, it's saying you returned false.
      • null, sorry.
      • I think I know what's going on.
      • It's documented wrong.
      • I thought we moved it out of that place, but it's not.
      • I'll look at it in a few mins.
      • And fix it.
      • I'll need to go see when it changed.
      • butts_butts
        Oh? The request name or what?
      • arvindsv
        The problem is that there are two pieces of configuration.
      • One is the response to: go.plugin-settings.get-configuration
      • That is what shows up in the plugin settings.
      • A little gear next to the name of the plugin in Admin -> Plugins.
      • Second is for scm plugin config itself: https://developer.gocd.org/current/writing_go_p...
      • Can you handle this and return empty ({}), please?