restgithubjenkinsgithub-apigithub-services

Github Service (Jenkins) Using Rest API


We are using Github API https://api.github.com/repos/:owner/:repo/hooks to create the Jenkins service in the repositoy. We are sending the following body

{
  "name": "jenkins",
  "active": true,
  "events": [
    "push",
    "pull_request"
  ],
  "config": {
    "url": "https://anon.com/jenkins/folder1/job/folder2/",
    "content_type": "json"
  }
}

When we are using Rest Client to invoke the above API then we are getting the service created in the repository but the url field is coming blank as shown below:

enter image description here


Solution

  • The above problem was caused due to mistake in in the body. The correct body for Jenkins service using Github Create hook API is-

    { 
    "name": "jenkins", 
    "active": true, 
    "events": [ 
        "push"
    ], 
    "config": { 
        "jenkins_hook_url": "https://anon.com/jenkins/folder1/job/folder2/"
    } 
    

    }

    The differences between this body and the body posted in the question are in the events object and config object.

    Since we are adding a service which will invoke For eg- a job in jenkins - only event which is required is push and not pull. Also in config object the parameter's key is jenkins_hook_url not url.