user4925383
user4925383

Reputation:

Jenkins plugin development - customizing default behaviour of Pipeline Snippet Generator

There is a snippet generator available under the following url:

http://<your-jenkins-instance>/job/<your-job>/pipeline-syntax/

It will generate the pipeline step snippet based on the data you enter on a form. Let's look at libraryResource step, as that will be a good example. If we do not fill in Character encoding, it will not be included in the generated snippet. This the behaviour I'm trying to implement in a custom plugin, to no avail. The way it works in my plugin is that every unset variable is always translated into empty in the generated snippet, e.g. value: '' rather than omited altogether.

I have been looking at the code and cannot find anything that would override the default behaviour that I've observed:

https://github.com/jenkinsci/workflow-cps-global-lib-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/workflow/libs/ResourceStep/config.jelly

https://github.com/jenkinsci/workflow-cps-global-lib-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/libs/ResourceStep.java

Any clues how to enforce skipping unset values while generating the snippet?

Upvotes: 1

Views: 311

Answers (1)

snieguu
snieguu

Reputation: 2283

In general, value is skipped during the generation of snippet if it is null, so in case of ResourceStep.encoding it is converted to null in method

@DataBoundSetter public void setEncoding(String encoding) {
    this.encoding = Util.fixEmptyAndTrim(encoding);
}

see https://github.com/jenkinsci/workflow-cps-global-lib-plugin/blob/workflow-cps-global-lib-2.15/src/main/java/org/jenkinsci/plugins/workflow/libs/ResourceStep.java#L67

More information You can find here: https://jenkins.io/doc/developer/plugin-development/pipeline-integration/

Upvotes: 0

Related Questions