[Question] Evaluate env var in text box to populate drop down list

54 views
Skip to first unread message

JordanGS

unread,
Apr 5, 2017, 8:08:22 PM4/5/17
to Jenkins Developers
I have two elements, a text box which takes a path and a drop down list below it that will populate the drop down list. How do i modify the doFill Items method to expand the value. See below method

zapSettingsDir is the textbox with the path from the jelly config file.

  <f:section title="${%ZAP Settings}">
   
<f:entry title="${%Path}" field="zapSettingsDir">
     
<f:textbox clazz="required" />
   
</f:entry>
 
</f:section>

and the associated java code is

        public ListBoxModel doFillActiveScanPolicyItems(@QueryParameter String zapSettingsDir) {
           
ListBoxModel items = new ListBoxModel();

           
/* No workspace before the first build, so workspace is null. */
           
if (workspace != null) {
               
File[] listFiles = {};
               
try {
                    listFiles
= workspace.act(new PolicyFileCallable(zapSettingsDir));
               
}
               
catch (IOException e) {
                    e
.printStackTrace(); /* No listener because it's not during a build but it's on the job config page. */
               
}
               
catch (InterruptedException e) {
                    e
.printStackTrace(); /* No listener because it's not during a build but it's on the job config page. */
               
}

                items
.add(""); /* To not load a policy file, add a blank choice. */

               
for (File listFile : listFiles)
                    items
.add(FilenameUtils.getBaseName(listFile.getName())); /* Add policy files to the list, without their extension. */
           
}
           
return items;
       
}

My problem being that i have no build variable at the moment and no listener since it's not at the build step yet but on the job's config page. Thanks :)

Joseph P

unread,
Apr 6, 2017, 1:33:31 AM4/6/17
to Jenkins Developers

Goran Dev

unread,
Apr 6, 2017, 1:42:45 AM4/6/17
to Jenkins Developers
The field attribute above is a text box that provides a path, in the form of an environment variable.

The do fill provides information for the drop down list


            <
f:entry title="${%Policy}" field="activeScanPolicy">
               <
f:select />
            </
f:entry>

As you can see, it's properly named. I'll try the posted link and update tomorrow on progress. I'm wondering how it will be able to evaluate the environment variable when it's on the slave and not the master while on the job config page and not in the build.

Cheers, Goran.
--
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/_SC7dwWpIb8/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/c4c89eb0-e4a2-4d97-83ee-b32cd14e54b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joseph P

unread,
Apr 6, 2017, 2:38:56 AM4/6/17
to Jenkins Developers
The config page only runs on master.
So if you need an environment variable from slave then you have to do some odd stuff :S

JordanGS

unread,
Apr 12, 2017, 7:09:22 PM4/12/17
to Jenkins Developers
You say odd stuff, but then that would make it possible? Do you have an example i can look at maybe?

Joseph P

unread,
Apr 13, 2017, 3:57:37 AM4/13/17
to Jenkins Developers
I would discourage against trying to grab something from slave nodes, how do you determine the right node? You can traverse all nodes but that seems a little over the top.
The two github links are examples of how to get a listener, and node (in this case Jenkins.instance can be casted to node) to access either files or command line tools or whatever have you.

JordanGS

unread,
Apr 13, 2017, 11:02:56 AM4/13/17
to Jenkins Developers
Fair point, i'll leave it alone. Thanks :)
Reply all
Reply to author
Forward
0 new messages