Difference between revisions of "Git"
(→Install Git) |
(→SSH) |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
== Install Git == |
== Install Git == |
||
− | On the Unix box, install Git. To do so, |
+ | On the Unix box, install Git. To do so, |
− | http://git-scm.com/book/en/v2/Getting-Started-Installing-Git] |
+ | [http://git-scm.com/book/en/v2/Getting-Started-Installing-Git follow this link: ] |
== Git User == |
== Git User == |
||
A Git user must be provided by the development organization. This Git user must have <b>clone, pull, and push</b> access to the projects' repositories to be on-boarded. This Git user is used for <b>all</b> projects. |
A Git user must be provided by the development organization. This Git user must have <b>clone, pull, and push</b> access to the projects' repositories to be on-boarded. This Git user is used for <b>all</b> projects. |
||
− | Scripts started by the <code>jenkins</code> user clone and push to and from the repository; The Git user login and password must be set |
+ | Scripts started by the <code>jenkins</code> user clone and push to and from the repository; The Git user login and password must be set |
− | [https://confluence.atlassian.com/display/STASH/Permanently+authenticating+with+Git+repositories#PermanentlyauthenticatingwithGitrepositories-Usingcredentialcaching] |
+ | [https://confluence.atlassian.com/display/STASH/Permanently+authenticating+with+Git+repositories#PermanentlyauthenticatingwithGitrepositories-Usingcredentialcaching as per this page:] |
== Storing the Git Credentials== |
== Storing the Git Credentials== |
||
− | One possibility is to store the Git credentials on the command line as the Jenkins user that runs the scripts. To do so, please refer to the [https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage Git Tools Credentials |
+ | One possibility is to store the Git credentials on the command line as the Jenkins user that runs the scripts. To do so, please refer to the [https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage Git Tools Credentials] documentation page: |
* ''The '''store''' mode saves the credentials to a plain-text file on disk, and '''they never expire'''. This means that until you change your password for the Git host, you won’t ever have to type in your credentials again.'' |
* ''The '''store''' mode saves the credentials to a plain-text file on disk, and '''they never expire'''. This means that until you change your password for the Git host, you won’t ever have to type in your credentials again.'' |
||
Line 22: | Line 22: | ||
== SSH == |
== SSH == |
||
− | One possibility is to have a user (jenkins on a CI) have an SSH key to be added to the GitHub account for that Linux user. For instance, log in as 'jenkins' on the CI system. Then generate an SSH |
+ | One possibility is to have a user (jenkins on a Continuous Integration (CI) system) have an SSH key to be added to the GitHub account for that Linux user. For instance, log in as 'jenkins' on the CI system. Then generate an SSH key if it does not already exist, and add the SSH key to the GitHub account. To do so, follow the instructions listed at |
+ | * https://help.github.com/articles/generating-an-ssh-key/ . |
||
+ | |||
+ | If connections are required with multiple users or multiple Git repository hosting system, please follow the link on how to manage multiple accounts: |
||
+ | * https://www.attosol.com/manage-multiple-git-accounts/ |
||
== .netrc == |
== .netrc == |
||
Line 39: | Line 43: | ||
git config --global user.name "Your Name" |
git config --global user.name "Your Name" |
||
</pre> |
</pre> |
||
+ | |||
+ | In 2021, GitHub depreciated the use of the password and instead recommends using a personal access token instead or other authentication methods. To create a token, follow [https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token these steps]. Save the token after creating it. Then in the <code>~jenkins/.netrc</code> file, replace the password with the new token. |
||
+ | <pre> |
||
+ | machine github.com |
||
+ | login gitUserName |
||
+ | password <personal access token> |
||
+ | </pre> |
||
+ | |||
+ | On the command line, if prompted for a password, use the token instead. |
||
== Test == |
== Test == |
Latest revision as of 20:22, 1 April 2022
Install Git
On the Unix box, install Git. To do so, follow this link:
Git User
A Git user must be provided by the development organization. This Git user must have clone, pull, and push access to the projects' repositories to be on-boarded. This Git user is used for all projects.
Scripts started by the jenkins
user clone and push to and from the repository; The Git user login and password must be set
as per this page:
Storing the Git Credentials
One possibility is to store the Git credentials on the command line as the Jenkins user that runs the scripts. To do so, please refer to the Git Tools Credentials documentation page:
- The store mode saves the credentials to a plain-text file on disk, and they never expire. This means that until you change your password for the Git host, you won’t ever have to type in your credentials again.
For example,
git config --global credential.helper store
To test the credentials, execute a git clone
(or git pull
, etc.) command as the Jenkins Linux user: It will ask you for a username password at the prompt. Once that's entered, re-run a git clone
(or git pull
, etc.) command: This time, the user should not be prompted for the username password.
This method may work in some cases better than the methods below, for example in some cases with Git over TFS.
SSH
One possibility is to have a user (jenkins on a Continuous Integration (CI) system) have an SSH key to be added to the GitHub account for that Linux user. For instance, log in as 'jenkins' on the CI system. Then generate an SSH key if it does not already exist, and add the SSH key to the GitHub account. To do so, follow the instructions listed at
If connections are required with multiple users or multiple Git repository hosting system, please follow the link on how to manage multiple accounts:
.netrc
A possible alternative to the SSH key route is using .netrc.
The following is an example of a ~jenkins/.netrc
file on Unix:
machine github.com login gitUserName password gitPassword
And on the command line, make sure the following is entered:
git config --global user.email "you@example.com" git config --global user.name "Your Name"
In 2021, GitHub depreciated the use of the password and instead recommends using a personal access token instead or other authentication methods. To create a token, follow these steps. Save the token after creating it. Then in the ~jenkins/.netrc
file, replace the password with the new token.
machine github.com login gitUserName password <personal access token>
On the command line, if prompted for a password, use the token instead.
Test
Make sure you can clone some repository using git clone, without having to enter at the prompt the login and password of the Git user.