Get pipeline and stages values from a task plugin

30 views
Skip to first unread message

Jurica (SuperJura)

unread,
Apr 14, 2023, 8:13:32 AM4/14/23
to go-cd
Hello,
I am trying to create a Discord plugin as a task plugin. It should send a message to discord webhook with data about all previous stages and Material changes that triggered the pipeline. 

I have 90% of it done, but I am missing how can I get the previous stages info from plugin. I tried to query requestBody, but it has only environment variables and config for Discord webhook. I uploaded the body contents I am getting.

Basically, I need this Json. Any idea how to get it?
{
  "PipelineChange":
  [
    {
      "Index": 111,
      "Author": "John",
      "Changed_Files":[
        "Assets/Code/Test.cs",
        "Assets/Code/Foo.cs"
      ]
    },
    {
      "Index": 112,
      "Author": "Jane",
      "Changed_Files":[
        "Assets/Code/Bar.cs"
      ]
    }
  ],
  "Previous_Stages":[
    {
      "Name": "Build Windows",
      "State": "Passed"
    },
    {
      "Name": "Build Mac",
      "State": "Failed"
    }
  ]
}

bodyContent.txt

Chad Wilson

unread,
Apr 14, 2023, 9:47:07 AM4/14/23
to go...@googlegroups.com
Plugins only receive certain data defined by the plugin APIs and relevant to that type of plugin. Conceptually you could query the web APIs from within any type of plugin, but that would probably make more sense from a notification plugin (runs on the server) rather than a task plugin (runs on an agent)?.

Notification plugins operate at stage level, not pipeline level and inform the server which pipelines they are interested in. Task plugins need to be added to individual pipelines/stages/jobs as steps so the config would live "inside" the pipeline.
- https://github.com/ashwanthkumar/gocd-slack-build-notifier uses the "hybrid notification plugin+calls back to web API for additional info" approach for Slack and Teams. You could fork it and/or add Discord integration if it looks close to what you want to achieve.

Don't think any plugin-based approaches will give you out-of-the-box information about previous stages in one message - you'd just send one notification per stage completion, generally.

-Chad

--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/go-cd/9cdce37c-de8f-472b-a6a6-5568226f55f5n%40googlegroups.com.

Jurica (SuperJura)

unread,
Apr 17, 2023, 5:36:53 AM4/17/23
to go-cd
Thanks for the info.

I would like a task plugin because it is more flexible in configuration. I can setup the config so every task has different webhook. As far as I know, notification plugins have "global" config and cannot be tweaked per pipeline.

I guess I'll query web API to get all the information.

Jurica (SuperJura)

unread,
Apr 26, 2023, 6:26:22 AM4/26/23
to go-cd
So I managed to make the plugin, and it works great.. when all of the tasks succeed. :)
As far as I am aware, GoCD cannot schedule a stage after previous job failed.
Just a long shot - is there a stage that will always be triggered no matter the previous outcomes?

If not, can you direct me to piece of code in the source where I could implement such stage?
I was thinking the stage would have "Finally" checkmark and if enabled, it will always be triggered.

Chad Wilson

unread,
Apr 26, 2023, 6:37:25 AM4/26/23
to go...@googlegroups.com
Individual tasks can be set to automatically run even if previous tasks in the same job failed (Run if Condition). That is probably the closest you are going to find, I believe.

Not for stages though. They can be configured to allow a manual trigger even if the previous stage has failed, but will not automatically trigger.

-Chad

Reply all
Reply to author
Forward
0 new messages