Dynamically populate drop down in builder interface

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamically populate drop down in builder interface

Marco Brondani
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

--
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically populate drop down in builder interface

stephenconnolly

On Sun 29 Oct 2017 at 06:43, 'Marco Brondani' via Jenkins Developers <[hidden email]> wrote:
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.

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 [hidden email].
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2BnPnMywMueDt_JJ9YBnobRG433MTmh5oKAmSi_oghVQ0RD_Fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Dynamically populate drop down in builder interface

Marco Brondani

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: [hidden email] <[hidden email]> on behalf of Stephen Connolly <[hidden email]>
Sent: Sunday, October 29, 2017 8:52:15 AM
To: [hidden email]
Subject: Re: Dynamically populate drop down in builder interface
 

On Sun 29 Oct 2017 at 06:43, 'Marco Brondani' via Jenkins Developers <[hidden email]> wrote:
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.

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 [hidden email].
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2BnPnMywMueDt_JJ9YBnobRG433MTmh5oKAmSi_oghVQ0RD_Fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/DB6PR04MB30628CCC4FA3BA60C2458BFCF5290%40DB6PR04MB3062.eurprd04.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically populate drop down in builder interface

Cameron Esfahani
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
[hidden email]

"Even paranoids have enemies."

Henry Kissinger



> On Nov 15, 2017, at 12:27 AM, 'Marco Brondani' via Jenkins Developers <[hidden email]> wrote:
>
> 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.-
>

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/2A605DED-1812-4BCA-B923-627C6F8CFCE3%40apple.com.
For more options, visit https://groups.google.com/d/optout.