Snippet Generator: any way to manipulate the format the "generate" button creates?

53 views
Skip to first unread message

Michael Carter

unread,
Aug 6, 2020, 8:54:48 AM8/6/20
to Jenkins Developers
I have a rather lengthy custom command I'm now writing, with ever growing nested items.  (Good comparison to what I'm writing is the recordIssues command).  The snippet Generator want's to all ways make it a single line 

eg:

recordIssues aggregatingResults: true, enabledForFailure: true, filters: [includeType('test')], qualityGates: [[threshold: 1, type: 'TOTAL', unstable: false], [threshold: 1, type: 'NEW_ERROR', unstable: false]], tools: [cpd(), checkStyle(), gendarme(pattern: '*.*')], trendChartType: 'TOOLS_ONLY'

What I'd like it to do for my command is something like:

recordIssues aggregatingResults: true,
             enabledForFailure
: true,
             filters
: [includeType('test')],
             qualityGates
: [[threshold: 1,
                             type
: 'TOTAL',
                             unstable
: false
                           
],
                           
[threshold: 1,
                             type
: 'NEW_ERROR',
                             unstable
: false
                           
]
                           
],
             tools
: [cpd(),
                     checkStyle
(),
                     gendarme
(pattern: '*.*')
                   
],
             trendChartType
: 'TOOLS_ONLY'

Anyone know a way to do this or how I can hook a formatter into it?  Is there custom hooks anywhere into the "Generate" button?

Jesse Glick

unread,
Aug 6, 2020, 1:05:52 PM8/6/20
to Jenkins Dev
On Thu, Aug 6, 2020 at 8:54 AM Michael Carter <mikeyca...@gmail.com> wrote:
> how I can hook a formatter into it? Is there custom hooks anywhere into the "Generate" button?

No, `workflow-cps` currently produces a single line only. I suppose it
could be made to generate indented multiline content if you checked a
box requesting that. What you _can_ do is ensure that default values
are omitted, so the size of the command is proportional to what the
user actually customized:

https://www.jenkins.io/doc/developer/plugin-development/pipeline-integration/#handling-default-values

Mark Waite

unread,
Aug 6, 2020, 1:56:53 PM8/6/20
to jenkinsci-dev
That page gave me hope that I might be able to remove the noisy default for generateSubmoduleConfiguration in the checkout scm generated code from the git plugin.  Unfortunately, it uses a boolean rather than a Boolean, so I don't think it can be null.  

Is there a way for me to hide the default value of a deprecated boolean field that intentionally has no jelly form associated with the field?
 

Jesse Glick

unread,
Aug 6, 2020, 2:25:23 PM8/6/20
to Jenkins Dev
On Thu, Aug 6, 2020 at 1:56 PM Mark Waite <mark.ea...@gmail.com> wrote:
> it uses a boolean rather than a Boolean, so I don't think it can be null.

Maybe it can be converted to `Boolean`? Generally this can be done
compatibly quite easily.

> Is there a way for me to hide the default value of a deprecated boolean field that intentionally has no jelly form associated with the field?

It should not be offered to begin with.
`DescribableModel.uninstantiate2` compares a fresh control instance
(created by calling the `@DataBoundConstructor`) with whatever form
submission produces, and only emits attributes for the diff. And it
ignores deprecated parameters.

Michael Carter

unread,
Aug 6, 2020, 6:12:52 PM8/6/20
to Jenkins Developers
It would be useful if it could produce multi-line.   All of the developers I see use it always take the single line, of the more complex plugins, then break it into a multi-line for easy reading.  

reportIssues of the Next Generation Warning is a good example.  Only one report tool it's small but after you start adding 10 or more tools with all the config it gets confusing and hard to read.

Jesse Glick

unread,
Aug 7, 2020, 9:39:48 AM8/7/20
to Jenkins Dev
On Thu, Aug 6, 2020 at 6:13 PM Michael Carter <mikeyca...@gmail.com> wrote:
> It would be useful if it could produce multi-line.

Feel free to file a PR with test coverage in `workflow-cps-plugin`. I
would suggest a GUI checkbox since for more typical short commands the
line break would just be annoying, and there is no obvious cutoff past
which multiline is clearly better.

(Also some plugins use `SnippetizerTester` to assert the Groovy
surface form of a given configuration, so behavioral changes would
force some test maintenance after updating the dep; not a big deal but
something to keep in mind.)

G. Michael Carter

unread,
Aug 7, 2020, 9:52:29 AM8/7/20
to jenkin...@googlegroups.com
Still grappling with this term "PR"?

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/_AAQThp4IIc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr12MAYQbvj6XR9Fb7Fxy%3DWDAOWKQUp6KdYJ-U0v_ctPRg%40mail.gmail.com.


--

G. Michael Carter

Contact: H: 1-647-277-1299 | M: 1-519-217-0441
Google Talk: xmpp:mikeyca...@gmail.com
Instagram:  mikey.carter

Jesse Glick

unread,
Aug 7, 2020, 10:18:39 AM8/7/20
to Jenkins Dev
On Fri, Aug 7, 2020 at 9:52 AM G. Michael Carter <mi...@carterfamily.ca> wrote:
> Still grappling with this term "PR"?

Pull request, sorry.

Eric Pyle

unread,
Aug 7, 2020, 10:24:23 AM8/7/20
to jenkin...@googlegroups.com
PR is short for Pull Request - a proposal for code change submitted for review.


On 8/7/2020 9:52 AM, G. Michael Carter wrote:
Still grappling with this term "PR"?

On Fri, Aug 7, 2020 at 9:39 AM Jesse Glick <jgl...@cloudbees.com> wrote:
On Thu, Aug 6, 2020 at 6:13 PM Michael Carter <mikeyca...@gmail.com> wrote:
> It would be useful if it could produce multi-line.

Feel free to file a PR with test coverage in `workflow-cps-plugin`. I
would suggest a GUI checkbox since for more typical short commands the
line break would just be annoying, and there is no obvious cutoff past
which multiline is clearly better.

(Also some plugins use `SnippetizerTester` to assert the Groovy
surface form of a given configuration, so behavioral changes would
force some test maintenance after updating the dep; not a big deal but
something to keep in mind.)

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/_AAQThp4IIc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr12MAYQbvj6XR9Fb7Fxy%3DWDAOWKQUp6KdYJ-U0v_ctPRg%40mail.gmail.com.


--

G. Michael Carter

Contact: H: 1-647-277-1299??| M: 1-519-217-0441
Google Talk: xmpp:mikeyca...@gmail.com
Instagram: ??mikey.carter
--
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/CANjusZcMYotBEfokcg8sXqx6rATjjGujffaEBCDqowsO78cuBg%40mail.gmail.com.


Virus-free. www.avast.com
Reply all
Reply to author
Forward
0 new messages