; Appointment: Midweek Aug 12 2020

Tags: Git

You might have a successfully executing build chore in Jenkins, then suddenly need that build task to push to a Github repository. For instance, information technology might render a statically generated website to push to the gh-pages branch for brandish using Github Pages. But this inscrutable fault message comes upwardly. In that location is a fairly simple fix, specially if you're using an HTTPS URL to access the Github repository.

In your normal user environment on your laptop you're probably using an SSH URL (git@github.com:{USER}/{REPO}.git) to access your repository. Merely on Jenkins, you lot're probably using an HTTPS URL instead (https://github.com/{USER}/{REPO}.git). This URL works nifty to clone the repository into a Jenkins workspace and perform a build. Merely as shortly as that chore needs to push button to a Github repository that URL volition not work because the HTTPS URL does not have hallmark.

On your normal user environment you might dimly call back how you ready remote Github access. That involves uploading an SSH public cardinal into the Github back-end for every account you have. Yous might try the same in the Jenkins environment, but that then relies on using the git@github.com:{USER}/{REPO}.git URL which might not work correctly in Jenkins. (I did not examination that)

1 option is to initialize a (git-scm.com) Git Credentials Store using a procedure like this:

                      $            git config credential.helper shop            $            git push            http://example.com/repo.git            Username:            <type            your username>            Countersign:            <type            your password>  [several days later on]            $            git push            http://example.com/repo.git [your credentials are used automatically]                  

This stores the user proper noun and password into ~/.git-credentials and is supposed to let you push to an HTTPS Git URL without entering a countersign. In my example this did not solve the outcome.

What worked for me was creating a Github Personal Admission Token and using an HTTPS URL that looks like this: https://{TOKEN}@github.com/{USER}/{REPO}.git

The personal access token is what it sounds similar, an encoded string that identifies you to Github. Information technology should be treated carefully, like a password, since that'south what it is. In my case I'chiliad the simply person using my Jenkins installation, so I just entered the URL as shown above into Jenkins. If this were a multi-person Jenkins installation there might exist a unlike all-time practice.

(docs.github.com) Github has instructions for setting upwardly the personal admission token. One goes to the Settings surface area, clicks on Developer Settings, and on the following page clicks on Personal Admission Tokens. That page has some clarification, then a push labeled Generate New Token.

While generating the token yous're given a long list of checkboxes. These make up one's mind the permissions levels associated with the token. In my case I simply clicked on the repo choice to give this token total permissions over repositories. The other permissions didn't seem appropriate. At the lesser is a button, Generate Token, that takes you to the access tokens dashboard, at which point you tin can copy the encoded string to the dashboard.

In Jenkins, become to the dashboard for 1 of your projects and click on the Configure button. In my projection, I have the Github URL in 2 locations -- I checked the Github project option, and entered the URL there -- and under Source Code Management I selected Git and entered the URL there.

The URL to enter has this format: https://{TOKEN}@github.com/{USER}/{REPO}.git

Later in the Jenkins chore, I'm having it poll the source repository every thirty minutes.

Finally, in the build section, I added the command that causes a push button to the Github repository. Prior to setting upward this personal access token, that control failed, but subsequently adding the token to the Github HTTPS URL, the control works.

Nigh the Author(southward)

David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind ability, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from email systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.

Ezoic