일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Spring
- java
- tool
- IntelliJ
- ubuntu
- elasticsearch
- Oracle
- ReactJS
- Git
- javascript
- springboot
- Spring Batch
- JVM
- Design Patterns
- 요리
- devops
- jsp
- Gradle
- Web Server
- laravel
- MySQL
- redis
- linux
- jenkins
- Spring Boot
- php
- it
- db
- AWS
- 맛집
- Today
- Total
아무거나
jenkins s3에 업로드하는 build 스크립트 소스 본문
#!/bin/bash
# $1:jenkins item name, $2:branch type, $3:s3 bucket object name
# ex) jenkins item name : ws_es_dev dev ws_es
if [ "$#" -ne 3 ];
then
echo "Bad Not Request Parameters"
else
# parameters check
if [ $2 = "dev" -o $2 = "stage" -o $2 = "master" ];
then
# aws config
jenkinsDir="/var/lib/jenkins/workspace"
jenkinsProjectDir="$jenkinsDir/$1"
s3Buckets="s3://ws.bucket/$3"
s3Region="ap-northeast-2"
# bucket object check
s3BucketObj=$(aws s3 ls $s3Buckets/)
s3BucketObjLen=${#s3BucketObj}
if [ $s3BucketObjLen -gt 0 ];
then
# composer install
cd $jenkinsProjectDir && composer install --prefer-dist
# master build
if [ $2 = "master" ];
then
current_version="0.0.0"
before_version="0.0.0"
# version file check
if [ -f "$jenkinsProjectDir/current_version.txt" ]
then
before_version=$(cat $jenkinsProjectDir/current_version.txt)
echo "current version : $before_version"
if [ $before_version = "9.9.9" ]; then
echo "---------------------------ERROR-----------------------------"
echo "-----------------------version full.........................."
echo "---------------------------ERROR-----------------------------"
exit
fi
else
echo "0.0.0" > $jenkinsProjectDir/current_version.txt
fi
aws s3 cp $s3Buckets/$3_$2_$current_version.tar.gz $jenkinsProjectDir/$3_$2_$current_version.tar.gz --region $s3Region
aws s3 cp $s3Buckets/$3_$2_$before_version.tar.gz $jenkinsProjectDir/$3_$2_$before_version.tar.gz --region $s3Region
# versioning
if [ -f "$jenkinsProjectDir/$3_$2_0.0.0.tar.gz" ];
then
vn=$(cd $jenkinsProjectDir/ && ls -td1 *.gz | head -n 1)
vc=$(echo $vn | cut -f 4 -d '_')
vMajor=$(echo $vc | awk '{ split($0, vArr, "."); print vArr[1] }')
vMinor=$(echo $vc | awk '{ split($0, vArr, "."); print vArr[2] }')
vPatch=$(echo $vc | awk '{ split($0, vArr, "."); print vArr[3] }')
# version terms
# patch
if [ $vPatch -ge 9 ]
then
vPatch=0
vMinor=$(($vMinor+1))
else
vPatch=$(($vPatch+1))
fi
# minor
if [ $vMinor -ge 9 ]
then
vMinor=0
vMajor=$(($vMajor+1))
fi
# major
if [ $vMajor -ge 9 ]; then
echo "Major Version Max Error"
fi
current_version=$vMajor.$vMinor.$vPatch
rm -r $jenkinsProjectDir/current_version.txt
echo $current_version > $jenkinsProjectDir/current_version.txt
rm -r $jenkinsProjectDir/$3_$2_0.0.0.tar.gz
rm -r $jenkinsProjectDir/$3_$2_$before_version.tar.gz
fi
cd $jenkinsProjectDir && tar -zcvf $jenkinsProjectDir/$3_$2_$current_version.tar.gz .
cd $jenkinsProjectDir && tar -zcvf $jenkinsProjectDir/$3_$2_latest.tar.gz .
aws s3 cp $jenkinsProjectDir/$3_$2_$current_version.tar.gz $s3Buckets/ --region $s3Region
aws s3 cp $jenkinsProjectDir/$3_$2_latest.tar.gz $s3Buckets/ --region $s3Region
rm -r $jenkinsProjectDir/$3_$2_$current_version.tar.gz
rm -r $jenkinsProjectDir/$3_$2_latest.tar.gz
# dev, stage build
else
version="0.0.0"
cd $jenkinsProjectDir && tar -zcvf $jenkinsProjectDir/$3_$2_$version.tar.gz .
aws s3 cp $jenkinsProjectDir/$3_$2_$version.tar.gz $s3Buckets/ --region $s3Region
rm -r $jenkinsProjectDir/$3_$2_$version.tar.gz
fi
else
# s3 bucket check
echo "S3Bucket Object empty!!!"
fi
else
echo "Bad Not Request Parameters( value = dev, master )"
fi
echo "$2 build finish !! [jenkins item : $1 , version : $current_version ] "
fi
'Infra > DevOps' 카테고리의 다른 글
slack을 이용하여 jenkins빌드 알람 설정 (0) | 2019.03.06 |
---|---|
jenkins git credentials 삭제 방법 (0) | 2019.03.06 |
jenkins 프로젝트 아이템 탭으로 그룹지정 (0) | 2019.03.06 |
jenkins 권한 관리 (0) | 2019.03.06 |
jenkins 버전 업그레이드 (0) | 2019.03.06 |