Skip to content

Instantly share code, notes, and snippets.

@ihoneymon
Created November 28, 2018 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihoneymon/80b059080654ef0bd6a190e04c13ff35 to your computer and use it in GitHub Desktop.
Save ihoneymon/80b059080654ef0bd6a190e04c13ff35 to your computer and use it in GitHub Desktop.

하나의 젠킨스에서 깃헙 저장소 여러 개를 빌드해야하는 경우

Note

젠킨스가 설치되어 있는 서버를 클라이언트로 보고 이 클라이언트에서 ssh 공개키를 여러벌 만들고 사용하는 저장소에 등록한 후 ssh Host 값을 가명(alias) 처리하여 젠킨스 한 곳에서 여러 저장소에 접근할 수 있도록 처리하는 방식이다.

  1. ssh key 생성

    $ ssh-keygen -t rsa -f id_rsa_{repo_name_1}
    $ ssh-keygen -t rsa -f id_rsa_{repo_name_2}
    
    // ex
    [] ~ ssh-keygen -t rsa -f id_rsa_test // (1)
    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in id_rsa_test.
    Your public key has been saved in id_rsa_test.pub.
    The key fingerprint is:
    SHA256:mTmXcyzRf9wX1MwxYEqZOHhsH0NkdfRDRCPJZqrCKqQ gimjiheon@gimjiheon-ui-MacBook-Pro.local
    The key's randomart image is:
    +---[RSA 2048]----+
    |        o +===*&o|
    |       . *o*o== B|
    |        o +.B  o.|
    |         + * . .+|
    |      . S * o . =|
    |   .   o + +   ..|
    |  o   . .        |
    | E . .           |
    |    .            |
    +----[SHA256]-----+
    [] ~ ssh-keygen -t rsa -f id_rsa_test_2  // (2)
    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in id_rsa_test_2.
    Your public key has been saved in id_rsa_test_2.pub.
    The key fingerprint is:
    SHA256:R3m/2/ayvMThpswtV9fnIVPpbqPhj8YIC0CgPnchyzA gimjiheon@gimjiheon-ui-MacBook-Pro.local
    The key's randomart image is:
    +---[RSA 2048]----+
    |   ..            |
    |  .  .     .     |
    | E ...    o .   .|
    |. + o..  . . . o |
    | o + .. S .   = .|
    |  o .  . o   = ==|
    |        . o o.Xo+|
    |         . +oO=*o|
    |            =*X*=|
    +----[SHA256]-----+
    1. id_rsa_testid-id_rsa_test.pub 파일 생성

    2. id_rsa_test_2id-id_rsa_test_2.pub 파일 생성

      id_rsa_test.pubid_rsa_test_2.pub 키를 각각 깃헙 저장소 deploy key 로 등록한다.

  2. ~/.ssh/config 파일 생성

    #test
    Host test
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_test
    
    #test2
    Host test2
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_test2
  3. . ~/.ssh/config 파일이 정상적으로 되었는지 확인

    $ ssh git@test // (1)
    PTY allocation request failed on channel 0
    Hi ihoneymon/test! You've successfully authenticated, but GitHub does not provide shell access.
    Connection to github.com closed.
    
    $ ssh git@test2 // (2)
    PTY allocation request failed on channel 0
    Hi ihoneymon/test2! You've successfully authenticated, but GitHub does not provide shell access.
    Connection to github.com closed.
    1. id_rsa_test 를 이용해서 정상적으로 가져올 수 있는지 확인

    2. id_rsa-test2 를 이용해서 정상적으로 가져올 수 있는지 확인

  4. Jenkins Credential 에 생성한 id_rsa_test, id_rsa_test2 에 대한 Credential 생성

    • Kind: SSH Username with private key

    • Private Key - Enter directly

      • 값은 cat id_rsa_test 를 통해 노출되는 값을 등록

  5. Jenkins Item - 'Source Code management' 에서 Repository URL 변경

    // 기존
    git@github.com:ihoneymon/test
    
    // 변경
    git@test:ihoneymon/test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment