Dynamically populate drop down in builder interface

35 views
Skip to first unread message

Marco Brondani

unread,
Oct 29, 2017, 2:43:30 AM10/29/17
to jenkin...@googlegroups.com
Hello,
I have a plug-in that uses Jenkins credentials to store API key and details necessary to make requests when the plug in runs.
However, to improve the Builder interface, I'd like to use the credentials to make a request to the API and automatically populate the drop down in the builder itself.
How can I do that?

The credentials are not accessible in the jelly so I can't just set a js script to make the Ajax.

Any help would be greatly helpful.

Thank you,
Marco

Stephen Connolly

unread,
Oct 29, 2017, 3:52:32 AM10/29/17
to jenkin...@googlegroups.com
It’s a fairly standard pattern, you just have the doFill___Items method in the DescriptorImpl reference the required fields with @QueryParam




Thank you,
Marco

--
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/HE1P195MB018878B3F690F248A739D586F5580%40HE1P195MB0188.EURP195.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

Marco Brondani

unread,
Nov 15, 2017, 3:36:30 AM11/15/17
to jenkin...@googlegroups.com

Hello All,

I have tried and followed the suggestion from Stephen.

Everything works well when I implement the doFill__Items from the Builder Descriptor.

I have however problems to retrieve the credentials when doing it from within an Action Descriptor.

 

In my builder I have:

 

<f:entry title=" Credentials" field="credentialsId">
    <
c:select />
</
f:entry>

<
f:block><p><strong> Action</strong></p></f:block>

<
f:entry title="${%Action}">
    <
f:dropdownDescriptorSelector field="action"
                                 
descriptors="${descriptor.getApplicableActions()}"/>
</
f:entry

 

Then, within my Actions I’d like to have

 

<f:entry title="Action configuration">
    <
f:entry title="Test ID" field="testId">
        <
f:select name="testId" default="noSuiteSelected"/>
    </
f:entry>

 

And in the doFillTestIdItems() make a request to the API with the data in credentials.

 

public ListBoxModel doFillTestIdItems(Build<?, ?> context, @QueryParameter String credentialsId) {

   
final CredentialImpl credential = CredentialsProvider.findCredentialById(credentialsId,
           
CredentialImpl.class, context, URIRequirementBuilder.create().build());

   
HandleAPI handleAPI = new HandleAPI(credential.getTeamSlug(), credential.getKeyId());
    this
.suitesResponse = (SuitesResponse)(handleAPI.callSuitesAPI());
   
ListBoxModel items = this.getListOfSuitesFromResponse(this.suitesResponse);

    return
items;
}

 

However this returns a java.lang.NullPointerException

 

Any help?

Anyone could point me to an example on GitHub that’s implemented similarly?

 

Thank you very much,

M.-

 


From: jenkin...@googlegroups.com <jenkin...@googlegroups.com> on behalf of Stephen Connolly <stephen.al...@gmail.com>
Sent: Sunday, October 29, 2017 8:52:15 AM
To: jenkin...@googlegroups.com
Subject: Re: Dynamically populate drop down in builder interface
 

Cameron Esfahani

unread,
Nov 15, 2017, 4:03:28 PM11/15/17
to jenkin...@googlegroups.com
If I understand your builder code, I think you need to refer to "credentialsId" with a @RelativePath.

Something like the following:

public ListBoxModel doFillTestIdItems(Build<?, ?> context, @QueryParameter( "credentialsId" ) @RelativePath( ".." ) final String credentialsId )
...

Cameron Esfahani
di...@apple.com

"Even paranoids have enemies."

Henry Kissinger
Reply all
Reply to author
Forward
0 new messages