# 젠킨스

### Download and run Jenkins

**httpPort 는 설정 할 수 있음 8081,8082... 등**

1. [Download Jenkins](http://mirrors.jenkins.io/war-stable/latest/jenkins.war).
2. Open up a terminal in the download directory.
3. Run `java -jar jenkins.war --httpPort=8080`.
4. Browse to `http://localhost:8080`.
5. Follow the instructions to complete the installation.
   1. Admin 비밀번호 입력, 읽어보면 다 가능
   2. 플러그인 디폴트 설치

### Maven 프로젝트 구성

1. Jenkins 관리 -> Plugin 관리 -> **Maven Integration** 설치(관련 내용 패키징 설치)
2. Jenkins 관리 -> **Global tool configuration** -> Maven -> **Maven 경로 설정 or 환경변수 설정** (system상)
   * **maven 설치**&#x20;
   * <http://maven.apache.org/download.cgi> **다운 및 scp 전송** -> 아래 내용으로 압축해
   * <http://maven.apache.org/download.cgi> 버전확인 후 **wget으로 다운**

     ```bash
     # (wget 플러그인 없는 경우)
     $ sudo yum install wget  

     # 다운로드
     $ wget http://mirror.apache-kr.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

     # 압축해제
     $ tar -xvzf apache-maven-3.6.3-bin.tar.gz

     # 경로 설정 .bashrc or .bash_profile
     $ vi ~/.bashrc
     export M2_HOME=[압축푼위치]
     export PATH=$PATH:$M2_HOME/bin

     # 반영
     $ source .bashrc 

     # 확인
     $ mvn -version
     ```
3. 대시보드 -> new item -> Maven 프로젝트
4. github 설정시 -> 서버에 git 설치 필요

   ```bash
   # 설치
   $ sudo yum install git

   # 확인
   $ git --version
   ```
5. 참조 : <https://medium.com/@anusha.sharma3010/build-a-simple-maven-project-in-jenkins-da7a2a4ae202>

### Github ssh key&#x20;

* 참조 : <https://kutar37.tistory.com/entry/Jenkins-Github-%EC%97%B0%EB%8F%99-%EC%9E%90%EB%8F%99%EB%B0%B0%ED%8F%AC-3>
* Username and Password -> github 로그인 정보인증 (보안 염려)&#x20;
* ssh key 인증
  * 서버 key 생성

    ```bash
    # ssh-keygetn -t rsa -f 파일명
    $ ssh-keygen -t rsa -f jenkins-github-key
    ```
  * 파일명.pub 공개키 정보(jenkins-github-key.pub) -> 복사 -> jenkins 인증 -> primary key 붙여넣기
  * Github -> Settings -> Deploy key -> .pub 키 복붙

### Github WebHook

* jenkins 빌드유발 내용 중 깃허브 변경사항 발생 시 조치하는 방법
* **jenkins 빌드유발부분 -> GitHub hook trigger for GITScm polling 체크**
* **github settings -> webhooks ->Payload URL : `Jenkins 주소/github-webhook/ 입력후 추가`**

### 빌드 후 조치&#x20;

* 자동배포&#x20;
