How to create a run object outside of a job?

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

How to create a run object outside of a job?

Michael Carter
The situation in a nut shell.   I've got a validation behind a button that calls a REST service to do the validation.   So the validation is happening outside any running job.

The only code I can find to lookup the password for the REST call is this one.

    StandardCredentials credResult = CredentialsProvider.findCredentialById(secretId,
                                                                           
StandardCredentials.class,
                                                                            run
,
                                                                           
Collections.<DomainRequirement>emptyList());


The run parameter can't be null.   So how do I create a dummy run job inside a Jenkins Plugin.   Or better yet create some type of run object that tells where it was running because I'd love to be able to track who's running the command against the credential.  (side project in another place)

--
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/61b1eb70-c200-4e7a-9a58-7849c2ef74ado%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to create a run object outside of a job?

Tim Jacomb
You can pass the Jenkins instance as the context.

Jenkins.get()

On Thu, 23 Jul 2020 at 13:51, Michael Carter <[hidden email]> wrote:
The situation in a nut shell.   I've got a validation behind a button that calls a REST service to do the validation.   So the validation is happening outside any running job.

The only code I can find to lookup the password for the REST call is this one.

    StandardCredentials credResult = CredentialsProvider.findCredentialById(secretId,
                                                                           
StandardCredentials.class,
                                                                            run
,
                                                                           
Collections.<DomainRequirement>emptyList());


The run parameter can't be null.   So how do I create a dummy run job inside a Jenkins Plugin.   Or better yet create some type of run object that tells where it was running because I'd love to be able to track who's running the command against the credential.  (side project in another place)

--
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/61b1eb70-c200-4e7a-9a58-7849c2ef74ado%40googlegroups.com.

--
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/CAH-3Bic1PZPCmrv84YFZvkgMdnEnUaWL0rHnFF_Y6%3DF9iJVupQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to create a run object outside of a job?

Jesse Glick-4
In reply to this post by Michael Carter
On Thu, Jul 23, 2020 at 8:51 AM Michael Carter
<[hidden email]> wrote:
>     StandardCredentials credResult = CredentialsProvider.findCredentialById(secretId,
>                                                                             StandardCredentials.class,
>                                                                             run,
>                                                                             Collections.<DomainRequirement>emptyList());
>
> The run parameter can't be null.   So how do I create a dummy run

You cannot. You must not use that method. Find another.

--
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/CANfRfr35n5P9S1%2BbTDUR%3Do%2Bh1np%3D1Hao-ezmN%3DgGsOGEzabU_A%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to create a run object outside of a job?

Michael Carter
Kind ironic first answer was more helpful because it when it didn't work it forced me to look at the code behind findCredentialById and to this code:

    List<IdCredentials> candidates = new ArrayList<>(
                   
CredentialsProvider.lookupCredentials(MyCredentialsImpl.class, (Item)null, null, Collections.<DomainRequirement>emptyList())
                   
);


   
return Test(secretId, (MyCredentialsImpl)CredentialsMatchers.firstOrNull(candidates, CredentialsMatchers.withId(secretId)));


And your answer was the cold water that I needed to use it.  ;)

Thanks for the help.

On Thursday, July 23, 2020 at 9:39:44 AM UTC-4, Jesse Glick wrote:
On Thu, Jul 23, 2020 at 8:51 AM Michael Carter
<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="-OZ-8webCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mikeyca...@...> wrote:
>     StandardCredentials credResult = CredentialsProvider.findCredentialById(secretId,
>                                                                             StandardCredentials.class,
>                                                                             run,
>                                                                             Collections.<DomainRequirement>emptyList());
>
> The run parameter can't be null.   So how do I create a dummy run

You cannot. You must not use that method. Find another.

--
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/8b123f81-c5c2-4a1f-8dee-4e42c3f2cae4o%40googlegroups.com.