2019년 10월 1일 화요일

jenkins 설치 및 기동 종료 스크립트

jenkins는 오픈소스 application을 빌드하기 위한 툴이다.
jenkins를 잘 활용 한다면 자동화 및 Continuous Integration (CI) / Continuous Delivery (CD)를 유용하게 사용할 수 있다. (지속적인 통합, 자동 배포 의미)

설치는 상당히 쉽다
https://jenkins.io/doc/pipeline/tour/getting-started/

문서의 내용을 살펴보면

하드웨어는 램 256mb, 디스크 10gb 정도이,
java 8 이상 버전, 컨테이너로 만드려면 docker가 필요하다

난 java로 띄워서 사용할 것이기 때문에 docker는 스킵한다.

1. http://mirrors.jenkins.io/war-stable/latest/jenkins.war 파일을 다운로드 받는다. wget으로 받는 방법, ftp로 업로드 하는 방법 선택하면 된다.
2. jenkins를 기동할 서버에 접속하여 jenkins.war 파일을 올려둔 경로로 이동한다.
3. java는 설치 했다 가정하고 아래의 명령어를 실행한다. (나같은 경우 openjdk 8설치)
   java -jar jenkins.war --httpPort=8080
4. 브라우저 열어서 http://serverip:8080 접속한다.
5. 브라우저 시키는대로 하면 끝

위와 같이 설치가 끝났다.
jenkins는 재기동 할일이 거의 없다. 하지만 하다보면 재기동할 경우도 많기 때문에 매번 java -jar ..... 이렇게 실행 시킬순 없다. 또한 종료는 어떻게 해야하는건지 내용은 안보인다.
사실 jenkins wiki에 있지만, 잘안된다. (jenkins wiki: https://wiki.jenkins.io/display/JENKINS/Administering+Jenkins)

그래서 기동 스크립트를 만들고 종료의 경우에는 jenkins-cli.jar 를 사용 해보려고 한다.
 jenkins-cli.jar 파일은 $JENKINS_HOME/war/WEB-INF 경로에 있다.

java -jar jenkins-cli.jar -s http://localhost:8080/ help
위와 같이 실행하면 옵션들이 보인다.
Options:
 -s URL              : the server URL (defaults to the JENKINS_URL env var)
 -http               : use a plain CLI protocol over HTTP(S) (the default; mutually exclusive with -ssh)
 -ssh                : use SSH protocol (requires -user; SSH port must be open on server, and user must have registered a public key)
 -i KEY              : SSH private key file used for authentication (for use with -ssh)
 -noCertificateCheck : bypass HTTPS certificate check entirely. Use with caution
 -noKeyAuth          : don't try to load the SSH authentication private key. Conflicts with -i
 -user               : specify user (for use with -ssh)
 -strictHostKey      : request strict host key checking (for use with -ssh)
 -logger FINE        : enable detailed logging from the client
 -auth [ USER:SECRET | @FILE ] : specify username and either password or API token (or load from them both from a file);
                                 for use with -http.
                                 Passing credentials by file is recommended.
                                 See https://jenkins.io/redirect/cli-http-connection-mode for more info and options.

난 -auth 를 사용했다.
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth admin:admin 

위와 같이 하게 되면 명령어 리스트가 보인다 여기서 shutdown이 있기 때문에 이걸 사용한다.
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth admin:******** shutdown 

명령어 실행시 정상적으로 종료가 되는 것을 확인 할 수 있다.

그럼 이것을 토대로 쉘스크립트를 작성하겠다.

start.sh 스크립트

nohup java -jar -Xms2048m -Xmx2048m  /opt/jenkins/bin/jenkins.war --httpPort=8080 >> jenkins.out 2>&1 &


shutdown 스크립트

java -jar /opt/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/ -auth admin:******** shutdown

잘 동작하는 것 같다.



댓글 없음:

댓글 쓰기