简体   繁体   中英

Unable to connect to GitHub API: org.kohsuke.github.HttpException

My Primary doubt is how github authentication happens in jenkins?

Task: We have to establish connection in jenkins with github repo for "GitHub Pull Request Builder".

GitHub Auth ----> GitHub Server API URL: https://api.github.com (Why we are giving this value? We did not give any of repository name here, So, how authentication is happening?) ----> credentials: I have given mine and tested with "connect to API", Response is: Connected to https://api.github.com as null (null) login: {{ my_user_name }}

----> But if i give my colleague credentials (which are already listed under credentials) and tested with "Connect to API" then below error has been coming.

Unable to connect to GitHub API: org.kohsuke.github.HttpException: {"message":"Requires authentication","documentation_url":"https://docs.github.com/rest/reference/users#get-the-authenticated-user"

   GitHub Pull Request Builder
   GitHub Auth  
   GitHub Server API URL    https://api.github.com
   Help for feature: GitHub Server API URL
      Jenkins URL override  
   Help for feature: Jenkins URL override
   Shared secret    
   ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
   Help for feature: Shared secret
   Credentials  user_name/****** (github user)
   Add
   Help for feature: Credentials
   Test basic connection to GitHub          
   Error:       
       Connect to API
   Unable to connect to GitHub API: org.kohsuke.github.HttpException: {"message":"Requiresauthentication","documentation_url":"https://docs.github.com/rest/reference/users#get-the-authenticated-user"}

Could someone please help on this?

I found out, how you do it. Basically Jenkins doesn't like different access tokens in global and Job specific Authentication.

  1. Go to "Manage Jenkins" > "Configure System" > Scroll down to GitHub
  2. "Add Github Server" with API URL "https://api.github.com"
  3. As Credentials use your Personal Access Token from github as "Secret Text"
  4. Click "Test Connection" to verify it works.
  5. (optional) enable "Manage hooks" if you like
  6. "Save"/"Apply"
  7. Now you can go and setup the Github Organization in Jenkins, where you ->
  8. specifiy the the credentials as "Username with password", where username is your github username and password your personal access token. ID and description may be empty but could help to remember what the credentials are for.
  9. Make sure you set the "Owner" value correctly to a github profile your account has access to. (eg the same name as specified in the credentials)
  10. Configure the remainder of the github organization as you like
  11. "Save"/"Apply"

While connecting to github, you need to give credentials. For GitHub Pull Request Builder , you need to use access token for setting up credentials for a given Github Server API Url. Authentication is done based on your access token.

When you are creating a job, at that time you are required to give your github url . A job will be created for that particular github repository.

You can read more here .

Don't use your username and password. It doesn't work. Use a Personal access token from your Github account and use it as a secret text credential with Jenkins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM