Search code examples
githubjenkinsjenkins-pipelinejenkins-blueocean

Jenkins pipeline unable to connect to github PRIVATE repository


Pulled latest jenkins image in docker. Followed the steps of jenkins io. Jenkins runs fine, I am able to create builds which checkout git repos.

What doesn't seem to work, is to create a pipeline for a PRIVATE github repo. The documentation states:

  • create access token in github [OK]
  • use it to authenticate [OK]
  • choose company/project [OK]
  • choose multibranch repo [OK]
  • create pipeline [fails]

The wizard complains about that there is no existing Jenkinsfile in my repo. That's incorrect. I do have a Jenkinsfile, which is correct (generated by blueocean too). So I guess the fact the blueocean complains about missing Jenkinsfile is related to not being able to find the project/branches in github. Something with credentials no longer working?

Also, when I follow the steps and try to manually create the pipeline:

enter image description here

Again, a strange error message, again I guess related to something which is broken in credential management, either in jenkins <-> github, or blueocean <-> github.

Last, when I open the build (=pipeline) from jenkins dashboard, I can click on Scan repository log which at least states the error clearly.

ERROR: [Mon Jul 11 12:43:07 UTC 2022] Could not update folder level actions from source blueocean [Mon Jul 11 12:43:07 UTC 2022] Finished branch indexing. Indexing took 0.23 sec

FATAL: Invalid scan credentials when using anonymous access to connect to basprins/unode on https://api.github.com

Finished: FAILURE

Again, the Personal Access Token is good. I created one with ALL scopes enabled (max rights in my repo) just to be sure nothing is left unchecked. It is "good enough" to login and checkout the branch. It seems to fail with actually creating the pipeline. I have no clue what else can be wrong on my side.

I tried any combination of username/password (legacy email address username + legacy password, or my github username + personal access token, and all 4 possible combinations of the two username/password pairs). Nothing gives.

Is there anybody that can confirm (or deny?) that above is possible, or would be willing to reproduce it on your side? It's an no-brainer docker setup. All you need to create is some temporary PRIVATE github.

Looking forward to an actual answer!


Solution

  • I had the same error and it seems like the jenkins credentials for the personal access token are not getting created automatically. This is how you can check if your issue is the same as mine:

    • Open the configuration of the multibranch pipeline.
    • Go to branch sources and then check if there is a name in the dropdown for credentials.
    • If there is no name then it's the same issue.

    The following is what I did to fix it:

    • Click on Add and create a credential with the following values:
      • Kind: Choose the option username and password.
      • username: Enter the github username.
      • password: Enter the api token you created.
    • Create the credential by clicking on add.
    • Choose the credential in the dropdown credentials and save the configuration.
    • Go to the overview page for the multibranch pipeline (in the old jenkins, not blueocean) and click on Scan repository now to run the scan again with working credentials.

    The error should now be resolved.