Jenkins - Github Plugin - Using Personal Access Token (required after Aug 13, 2021 change)

16.6k Views Asked by At

We were using GitHub plugin with Username and password credentials so far in our Jenkins setup.

However, after Aug 13th, 2021, this stopped working raising this error:

stderr: remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.

As per the answer provided by in How to use Github Personal Access Token in Jenkins

I modified the URL to be:

https://<access token>@github.com/<userName>/<organization>/<repository>.git

but it did not work.

Am I missing any steps here?

4

There are 4 best solutions below

11
On BEST ANSWER

Create your Private access token using below URL

https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token

After that In Jenkins Job under Source Code Management section, provide Git repository URL in the format https://[email protected]/<Your_Org>/yourRepoName.git

e.g if Repo name is abc,Organization is test and Token number is 12345678 then URL will be look like

https://[email protected]/test/abc.git

Screenshot: Git Private Access Token binding

This method resolved my problem.

0
On

This is not about changing URL. Jenkins is clearly indicating that it needs a Personal Access Token(PAT) instead of a password for git authorization.

Please create a PAT using the below link: [https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token][1]

Then go to Jenkins -> Configure Job -> Source Code Management and Change the Repository URL as follow: https://[email protected]/<Your_Org>/yourRepoName.git

  • Access Token Number: Its a PAT that you will generate using above shared link

  • Organization Name: The global name under which your repositories exist

  • RepoName: Name of your repository for which Jenkins job is configured

1
On

Jenkins offers a credentials store where we can keep our secrets. Best practices to save it as local variable and concatenate the personal token on git URL "https://[email protected]/<Your_Org>/yourRepoName.git"

0
On

For a more scalable solution, define GitHub token once and use it multiple times (DRY). You can save it in Credentials (Jenkins's keyring).

Steps are as follows:

  1. Generate GitHub Personal Access Token, PAT (and save it somewhere safe):

Settings > Developer settings > Personal access tokens (link).

  1. Create a new Credential in Jenkins (of the "Username with Password" kind), entering GitHub PAT as password:

Manage Jenkins > Credentials > System > Global credentials > Add Credentials > Kind > Username and password (https://<JENKINS_URL>/manage/credentials/store/system/domain/_/).

  1. Use the new Credential in all pipelines that clone GitHub repos:

<PIPELINE_NAME> > Configure > Pipeline > Definition > Pipeline script from SCM > SCM > Git > Credentials (https://<JENKINS_URL>/job/<PIPELINE_NAME>/configure).