๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/์„œ๋ฒ„ ํ™˜๊ฒฝ

[Jenkins] ์  ํ‚จ์Šค SVN Subversion ํ˜•์ƒ๊ด€๋ฆฌ ๋ฐฐํฌ ๋นŒ๋“œ :: ๋งˆ์ด์ž๋ชฝ

by ๐ŸŒปโ™š 2019. 5. 10.

์  ํ‚จ์Šค ํ”„๋กœ์ ํŠธ ๋“ฑ๋ก(SVN)

ํ”„๋กœ์ ํŠธ ์„ธํŒ…ํ•˜๋ฉด์„œ ์  ํ‚จ์Šค์— SVN ์—ฐ๋™ํ•˜์—ฌ ํ”„๋กœ์ ํŠธ ๋ฐฐํฌ ๋นŒ๋“œํ•˜๋Š”๋ฐ ์• ๋จน์€ ์  ์žˆ๋‹ค.
์•„๋ž˜ ๋‚ด์šฉ๋Œ€๋กœ๋งŒ ๋”ฐ๋ผํ•˜๋ฉด ๋ฌธ์ œ์—†์ด SVN์œผ๋กœ ํ˜•์ƒ๊ด€๋ฆฌํ•˜๊ณ  ์  ํ‚จ์Šค๋กœ ๋นŒ๋“œํ•˜๋Š” ์ž‘์—…์„ ์‰ฝ๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.

์  ํ‚จ์Šค์™€ SVN์ด ์„œ๋ฒ„์— ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด ์•„๋ž˜ ๋งํฌ๋ฅผ ํ†ตํ•ด์„œ ์„ค์น˜ํ•˜์ž.
์•„๋ž˜ ๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰ํ•˜๊ธฐ ์ „์— ์„ค์น˜์™€ SVN์— ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋‚˜ ์˜ฌ๋ฆฐ ์ƒํƒœ์—์„œ ์ง„ํ–‰ํ•œ๋‹ค.

์  ํ‚จ์Šค ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

์  ํ‚จ์Šค ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
์ƒˆ๋กœ์šด Item ํด๋ฆญ!


ํ”„๋กœ์ ํŠธ ๋ช…์„ ์ž…๋ ฅํ•ด์ฃผ๊ณ  Freestyle project ์„ ํƒ ํ•œ ํ›„ ๋‹ค์Œ์œผ๋กœ ์ง„ํ–‰!





์  ํ‚จ์Šค ํ”„๋กœ์ ํŠธ ์„ค์ •

์†Œ์Šค์ฝ”๋“œ ๊ด€๋ฆฌ ๋ถ€๋ถ„์—์„œ svn์˜ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๊ณ  ๊ถŒํ•œ์„ ๋“ฑ๋กํ•ด์ค˜์•ผํ•œ๋‹ค.
์•„์ด๋”” ๋“ฑ๋ก์„ ์œ„ํ•ด  Add ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ ๊ถŒํ•œ ์ƒ์„ฑํ•œ๋‹ค.




Cridentials ๋“ฑ๋ก

๊ถŒํ•œ์€  svn ์•„์ด๋””์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ๋“ฑ๋กํ•ด์ค€๋‹ค.




์  ํ‚จ์Šค ๋นŒ๋“œ

๋นŒ๋“œ๋ฅผ ์„ค์ •ํ•ด์ค€๋‹ค.
invoke top-level Maven targets์˜ Goal์„ clean install๋กœ ์„ค์ •ํ•ด์ฃผ๊ณ  Execute Shell์„ ์„ค์ •ํ•ด์ค€๋‹ค.
์‰˜ํŒŒ์ผ ์‹คํ–‰ํ•˜๋Š” ์ด์œ ๋Š” WAS ํ†ฐ์บฃ์„ ์ •์ง€ ์‹œํ‚ค๊ณ , svn์—์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฐ›์•„์™€ ํ†ฐ์บฃ์— ๋ฐฐํฌ์‹œํ‚ค๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋”ฐ๋กœ ์‰˜ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ์ค˜์•ผํ•œ๋‹ค.


Execute Shell

1
sudo -/home/jamong/dev/jenkins_sudo_similarQuery.sh
cs



์‰˜ํŒŒ์ผ ๋‚ด์šฉ

/home/jamong/dev ๊ฒฝ๋กœ์— ๋ฐฐํฌํ•  warํŒŒ์ผ์„ ์ €์žฅํ•ด๋†“์„๊ฑฐ๋‹ค.
tomcat์˜ ๊ฒฝ๋กœ๋Š” /home/jamong/dev_util/tomcat ์œผ๋กœ ์ง€์ •ํ•ด๋†จ๋‹ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
 
cd /home/jamong/dev_util/tomcat/bin
./shutdown.sh
 
sleep 10
 
cd /home/jamong/dev
rm -rf similarQuery-1.0.0.war
 
cd /home/jamong/dev_util/tomcat/webapps
rm -rf similarQuery
 
cp /home/jamong/.jenkins/workspace/similarQuery/target/similarQuery-1.0.0.war /home/jamong/dev/
 
cd /home/jamong/dev_util/tomcat/bin
./startup.sh
 
sleep 10 

cs




ํ†ฐ์บฃ server.xml์„ค์ •

๋งˆ์ง€๋ง‰์œผ๋กœ ํ†ฐ์บฃ ์„ค์ •ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์ค˜์•ผํ•œ๋‹ค.
dev ํด๋”์— ์žˆ๋Š” warํŒŒ์ผ์„ ๋ฐ”๋ผ๋ด์„œ WAS๊ฐ€ ์‹คํ–‰๋ ๋•Œ ํ•ด๋‹น ํŒŒ์ผ์ด ๋ฐฐํฌ๋˜๋„๋ก ์„ค์ •ํ•œ๋‹ค.
Host ํƒœ๊ทธ ์•ˆ์— Context๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ  reloadable ์ธ์ž๊ฐ’์„ true๋กœ ์„ค์ •ํ•œ๋‹ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
 
   <!-- SingleSignOn valve, share authentication between web applications
        Documentation at: /docs/config/valve.html -->
   <!--
   <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
   -->
 
   <!-- Access log processes all example.
        Documentation at: /docs/config/valve.html
        Note: The pattern used is equivalent to using pattern="common" -->
   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
          prefix="localhost_access_log" suffix=".txt"
          pattern="%h %l %u %t &quot;%r&quot; %s %b" />
 
   <Context path="/similarQuery" docBase="/home/jamong/dev/similarQuery-1.0.0.war" reloadable="true"/>
</Host>

cs



๋นŒ๋“œ

์ด์ œ ๋ชจ๋“  ์„ค์ •์€ ๋๋‚ฌ๊ณ  ๋นŒ๋“œ๋ฅผ ์ง„ํ–‰ํ•ด์ค€๋‹ค. ์•„๋ž˜ ์ฒ˜๋Ÿผ ํŒŒ๋ž€์ƒ‰ ๋ถˆ์ด ๋“ค์–ด์˜ค๋ฉด ๋นŒ๋“œ ์„ฑ๊ณต์ด๋‹ค.
์ถ”๊ฐ€์ ์œผ๋กœ ํ™•์ธ ํ•ด์ค˜์•ผํ•  ๊ฒƒ์€ ๋นŒ๋“œ๊ฐ€ ์™„๋ฃŒ ๋˜์—ˆ์ง€๋งŒ, ์‰˜ํŒŒ์ผ์ด ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰์ด ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด์ค˜์•ผํ•œ๋‹ค.
๊ฐ„ํ˜น ๋นŒ๋“œ์‹œ ์ด๋ฆ„์„ ์ž˜๋ชป ์ž…๋ ฅํ–ˆ๊ฑฐ๋‚˜ ํ•˜๋Š” ๊ฒฝ์šฐ์— ํ”„๋กœ์ ํŠธ๊ฐ€ ์•ˆ์˜ฌ๋ผ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.





pom.xml

ํ”„๋กœ์ ํŠธ์˜ pom.xmlํŒŒ์ผ์—์„œ artifactID์™€ version์— ๋”ฐ๋ผ ๋นŒ๋“œ์‹œ ๋งŒ๋“ค์–ด์ง€๋Š” ํƒ€๊ฒŸ ๋ช…์ด ๊ฒฐ์ •๋œ๋‹ค.
์•„๋ž˜๊ฐ™์€ ๊ฒฝ์šฐ๋Š” similarQuery-1.0.0.war๋กœ ๋ฐฐํฌํŒŒ์ผ์ด ๋งŒ๋“ค์–ด์ง„๋‹ค.
1
2
3
4
5
6
<modelVersion>4.0.0</modelVersion>
    <groupId>com.similar</groupId>
    <artifactId>similarQuery</artifactId>
    <name>similarQuery</name>
    <packaging>war</packaging>
    <version>1.0.0</version>
cs


๋Œ“๊ธ€