Dynamically populate drop down in builder interface

已查看 35 次
跳至第一个未读帖子

Marco Brondani

未读,
2017年10月29日 02:43:302017/10/29
收件人 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

未读,
2017年10月29日 03:52:322017/10/29
收件人 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

未读,
2017年11月15日 03:36:302017/11/15
收件人 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

未读,
2017年11月15日 16:03:282017/11/15
收件人 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
回复全部
回复作者
转发
0 个新帖子