How to create a run object outside of a job?

6 views
Skip to first unread message

Michael Carter

unread,
Jul 23, 2020, 8:51:40 AM7/23/20
to Jenkins Developers
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)

Tim Jacomb

unread,
Jul 23, 2020, 8:54:02 AM7/23/20
to Jenkins Developers
You can pass the Jenkins instance as the context.

Jenkins.get()

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

Jesse Glick

unread,
Jul 23, 2020, 9:39:44 AM7/23/20
to Jenkins Dev
On Thu, Jul 23, 2020 at 8:51 AM Michael Carter
<mikeyca...@gmail.com> 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.

Michael Carter

unread,
Jul 23, 2020, 10:49:22 AM7/23/20
to Jenkins Developers
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.
Reply all
Reply to author
Forward
0 new messages