Adding casc support to plugin

92 views
Skip to first unread message

Kirk Fitzsimons

unread,
Aug 19, 2024, 6:33:50 AM8/19/24
to Jenkins Developers
Hi,

I am trying to add casc support to Sonar Quality Gates plugin, this is my attempt.

Try add casc · kirk-fitz/sonar-quality-gates-plugin@ea75469 (github.com)

I can see the root of the plugin config, but I am not getting any properties, can someone help me identify what I am missing

"sonarQualityGates": {
                    "additionalProperties": false,
                    "type": "object",
                    "properties": {}
                },

Kirk

Winter, Markus

unread,
Aug 19, 2024, 6:48:52 AM8/19/24
to jenkin...@googlegroups.com

The class GlobalConfigDataForSonarInstance must be a Describable

See https://github.com/jenkinsci/configuration-as-code-plugin/blob/master/docs/PLUGINS.md#step-2

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/7132814d-69f0-4d35-ae2f-5aeb0e6e35fdn%40googlegroups.com.

Kirk Fitzsimons

unread,
Aug 19, 2024, 9:06:00 AM8/19/24
to Jenkins Developers
Thanks for the reply

Apologies, but I am very new to this, I have pushed a change to my branch, I must be missing something else

Ensure GlobalConfigDataForSonarInstance extends Describable · kirk-fitz/sonar-quality-gates-plugin@415ede3 (github.com)

Kirk

Winter, Markus

unread,
Aug 19, 2024, 11:54:17 AM8/19/24
to jenkin...@googlegroups.com

Took a look and tried things out:

You also need a DataBoundConstructor for the noarg contructor of GlobalConfig

And create a method “setListOfGlobalConfigData” and annotate as DataBoundSetter.

Remove the DataBoundSetter from setGlobalConfigDataForSonarInstances

 

The way of configuring with the GlobalConfigurationService might be a problem with CasC

 

Line 19 in GlobalConfig should be transient, it doesn’t contain data that should be saved

 

You can remove the wrapping table in config.jelly

Kirk Fitzsimons

unread,
Aug 19, 2024, 7:23:03 PM8/19/24
to Jenkins Developers

You can only have one  DataBoundConstructor  annotation i believe.
I removed the table from the config.jelly

I renamed the method  setGlobalConfigDataForSonarInstances to  setListOfGlobalConfigData

It looks like it is working now:

cascdoc.png

I was also able to export the casc

 sonarQualityGates:
    listOfGlobalConfigData:
    - maxWaitTime: 300000
      name: "test"
      timeToWait: 10000
    - maxWaitTime: 500000
      name: "test2"
      timeToWait: 20000


I think perhaps I need to look at the naming convetion etc,  listOfGlobalConfigData doesnt sound descriptive, perhaps its should be listOfSonarInstances, or maybe just sonarInstances

Will also need to look into adding tests

Kirk Fitzsimons

unread,
Aug 20, 2024, 10:31:25 AM8/20/24
to Jenkins Developers
I have made some more updates and it appears to be working

https://github.com/kirk-fitz/sonar-quality-gates-plugin/commit/9043167264ff1106fc5ff58480b6ceb866982e92

Can somone suggest how I might add casc automation tests? I have added a template one, but im not sure how to instantiate my config etc before comparing it to the expected yaml config

Ullrich Hafner

unread,
Aug 20, 2024, 5:08:37 PM8/20/24
to jenkin...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages