티스토리 뷰

이번에 소개할 내용은 소스를 빌드하여 nexus에 배포를 하고 그 배포된 파일 목록을 Jenkins에서 가져와 원하는 파일로 was에 배포를 하는 것이다. 이게 뭐하는 일인가 싶을수도 있지만 was에 배포한 파일이 잘못되어서 긴급하게 예전 버전으로 복원을 하고 싶을때 아주 유용하게 사용할 수 있다. 


일단은 빌드를 할때 nexus에 배포를 하는 부분을 pom.xml에 추가를 해야 한다. 

 

pom.xml

<distributionManagement>
  <repository>
    <id>sample-repository-snapshot</id>
    <name>Public Repository</name>
    <url>http://repo.sample.co.kr:9090/repository/maven-releases/</url>
  </repository>

  <snapshotRepository>
    <id>sample-repository</id>
    <name>Public Repository(snapshot)</name>
    <url>http://repo.sample.co.kr:9090/repository/maven-snapshots/</url>
    <uniqueVersion>true</uniqueVersion>
  </snapshotRepository>
</distributionManagement>

pom.xml 의 배포관리자(distributionManagement) 에서 설치한 nexus에 프로젝트를 deploy 하기 위한 설정을 한다. 물론 repo.sample.co.kr:9090/repository/maven-releases/ 이런 nexus는 미리 설치가 되어 있어야 한다. nexus를 설치하는 방법은 다음 기회에 알아보도록 하겠다. pom.xml 에 이런 설정을 하면 nexus에 똭 붙느냐? 물론 아니다. nexus에 접근하기 위한 설정을 settings.xml 에서 해줘야 한다. 

 

settings.xml 

<servers>
  <server>
    <id>sample-repository-release</id>
    <username>id</username>
    <password>password</password>
  </server>
	
  <server>
    <id>sample-repository-snapshot</id>
    <username>id</username>
    <password>password</password>
  </server>
 ...
</servers>

이런식으로 배포를 할때 사용할 nexus에 대해서 정의를 해줄수 있다. 


nexus를 위한 배포 준비는 다 되었고 이제 maven build 하는 시점에 deploy를 해줘서 빌드하는 시점에 빌드한 파일이 nexus로 올라가게끔 해준다.

 

 

Goals and options 에서 deploy를 해서 빌드한 파일이 위에 설정한 nexus에 올라갈수 있도록 해준다. 

빌드를 하고 난 후 nexus에 들어가서 파일이 정상적으로 올라갔는지 확인해보자. 

 

배포할때마다 SNAPSHOT이 잘 생성이 되어 nexus로 등록이 된다. 빌드 할때마다 버전 관리가 잘 이루어지고 있다. 


이제 jenkins에서는 이 파일목록을 가지고 와서 내가 원하는 파일로 was에 deploy 하는 과정만 남았다. 

nexus에 등록된 파일을 가지고 오기 위해서는 다음과 같은 jenkins plugin이 필요하다. 

 

 

Extensible Choice Parameter

Extensible Choice Parameter provides several ways to retrieve choices, including the way to share choices among all jobs.

plugins.jenkins.io

Extensible Choice Parameter를 설치했으면 배포를 위한 새로운 Job을 만들자. 

 

 

이 빌드는 매개변수가 있습니다. > Extensible Choice 클릭 후 Choice Provider에 Nexus3 Artifact Choice Parameter를 선택한다. 필자는 Nexus3를 사용해서 이걸 선택했고 전버전을 사용한다면 그냥 Nexus로 선택한다. 이곳에 Nexus에 접근해서 가져오기 위한 정보들을 입력하고 List Files Now를 선택하면 빌드할때 생성되었던 war파일들이 쭉 나온다. 

 

 

curl -o [로컬에저장할파일명] [가져올파일명] 으로 내가 원하는 버전을 선택한걸 가져올수 있도록 한다. 그리고 나서 원하는 서버의 원하는 위치에 배포!


Build with Parameters 를 눌러서 FILE_LOC로 설정해 놓은 셀렉트박스를 열어보면 위와 같이 나오는걸 확인할 수 있다. 내가 원하는 파일을 골라서 빌드하기 누르면 된다. 

 

끝!

댓글
최근에 올라온 글
최근에 달린 댓글
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31