7

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?

mirekphd
  • 4,799
  • 3
  • 38
  • 59
Lakshmi
  • 81
  • 1
  • 1
  • 4
  • That is not what they say that the URL should be. What did you actually do? Where did you put the PAT? – fredrik Aug 17 '21 at 06:41
  • @fredrik - is where I had kept my PAT... reference - https://stackoverflow.com/questions/61105368/how-to-use-github-personal-access-token-in-jenkins . I also tried with a Jenkins 'Username-password' credential where password was my PAT. – Lakshmi Aug 17 '21 at 07:49
  • And what errors are you getting? – fredrik Aug 17 '21 at 07:52
  • 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. – Lakshmi Aug 17 '21 at 08:00

4 Answers4

17

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://access_Token_Number@github.com/<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://12345678@github.com/test/abc.git

Screenshot: Git Private Access Token binding

This method resolved my problem.

hussains8
  • 634
  • 6
  • 12
  • is there no need to append username in this URL ? – Lakshmi Aug 17 '21 at 08:37
  • yes, no need to append username. Only access token is all in one – hussains8 Aug 17 '21 at 08:39
  • @hussain8 - credentials to be set to None , is it ? – Lakshmi Aug 17 '21 at 08:40
  • yes no need to bind credentials in this case @Lakshmi – hussains8 Aug 17 '21 at 08:41
  • Ended up in error with provided url format .status code 128: stdout: stderr: fatal: Cannot prompt because user interactivity has been disabled. remote: Invalid username or password. fatal: Authentication failed for – Lakshmi Aug 17 '21 at 08:41
  • I'm not getting any error. can you please check either providing all required details and Token is not expired – hussains8 Aug 17 '21 at 08:47
  • I added screenshot in the answer post. have a look at this. I'm not getting any error – hussains8 Aug 17 '21 at 08:50
  • Token is with 'No expiration'. How do u know if your email address is verified or not ? Mine does not say its unverified but doesnt say verified as well. What was the scope you have selected for your PAT ? – Lakshmi Aug 17 '21 at 08:50
  • you will get an email on configured email address and details will be shared in the email either token created successfully or contact support in case of any problem. Try adding new Private access Token – hussains8 Aug 17 '21 at 08:53
  • This did work out for me finally !!! I re-generated a new token with scope of repo, admin-hook also added. – Lakshmi Aug 17 '21 at 08:58
  • happy to hear this. Please rate the answer so others can take advantage of that as well. – hussains8 Aug 17 '21 at 08:59
1

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://access_Token_Number@github.com/<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

Ali Iqbal
  • 91
  • 1
  • 6
1

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).

mirekphd
  • 4,799
  • 3
  • 38
  • 59
-1

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://access_Token_Number@github.com/<Your_Org>/yourRepoName.git"

Aymen Jarouih
  • 469
  • 5
  • 8
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 11 '22 at 15:44