Search code examples
jenkinsjenkins-workflowjenkins-pipeline

How to programmatically trigger a specific jenkins build managed via github-organization?


I am using the github-organization plugin to manage jenkins jobs from github but I discovered that Jenkins API does not report these builds.

In fact the API list the entire organization as a single job.

How can I build a specific repository and branch using the API?

To be clear, I am looking for some groovy code to add inside the Jenkinsfile

#!groovy

stage 'test-downstream'
node {
    def job = build job: 'some-job'
}

Now, the problem is that Jenkins is seeing the entire organization as a single job!

If I use Jenkins API to retrieve the jobs, it will return only the organization, and not all the repositories and jobs inside it.

I suspect that's because the way this plugin was implemented and I suppose that I need to give some extra parameters in order to specify which repository and branch I want to build inside the organization.... building an organization does not make much sense.


Solution

  • The question is vague, but I am guessing “API” in this context means the REST API to trigger builds. You can use for example

    curl -X POST -u user:apitoken http://jenkins/job/yourorg/job/yourrepo/job/master/build