Iterate trough all jobs and trigger one by name

13 views
Skip to first unread message

Daniel Anechitoaie

unread,
Apr 3, 2019, 12:47:30 PM4/3/19
to Jenkins Developers
I'm working on implementing a webhook for a plugin that should receive as param the name of the job it should trigger and some arguments for that job.
How can I iterate trough all the jobs in Jenkins from within a class implementing UnprotectedRootAction and how can I trigger a specific job by passing a param?

Basically I need to pass the commit that will be then used by git plugin to make a build from that specific commit.

Jesse Glick

unread,
Apr 3, 2019, 1:10:00 PM4/3/19
to Jenkins Dev
On Wed, Apr 3, 2019 at 12:47 PM Daniel Anechitoaie
<danie...@gmail.com> wrote:
> I need to pass the commit that will be then used by git plugin to make a build from that specific commit.

The `git` plugin already has such a hook. If for some reason you
cannot reuse it, study its code.

In general what you describe is a security risk. Your webhook needs to
demand some kind of proof that the caller is indeed authorized to
build that job, in that commit, with those parameters.

Daniel Anechitoaie

unread,
Apr 3, 2019, 1:20:45 PM4/3/19
to Jenkins Developers
I found how to iterate trough all the jobs "for (Job job : Jenkins.get().allItems(Job.class)) {" but I'm still having trouble how to trigger a job.
I'm trying to implement a GitHub App for the new GitHub PR checks API, so I will add security checks to make sure the requests are coming from a trusted source.

Jesse Glick

unread,
Apr 3, 2019, 1:25:09 PM4/3/19
to Jenkins Dev
On Wed, Apr 3, 2019 at 1:20 PM Daniel Anechitoaie <danie...@gmail.com> wrote:
> I'm still having trouble how to trigger a job.

Use `ParameterizedJob` methods.

Daniel Anechitoaie

unread,
Apr 3, 2019, 1:37:03 PM4/3/19
to Jenkins Developers
Thank you. I'll look into this.
Reply all
Reply to author
Forward
0 new messages