Commit 5b4d3e7a authored by Bùi Bá Trường's avatar Bùi Bá Trường

test

parent a7e09490
Pipeline #469 failed
......@@ -13,26 +13,21 @@ variables:
QUALITY_GATE: "OK"
stages:
- checkout
- checkout_code
- compile
- sonnar_scanner
- check_quality_gate
- dokcer_build
- docker_build
- docker_up
- docker_push
- send_email
checkout:
stage: checkout
checkout_code:
stage: checkout_code
only:
- master
- merge_request
script:
# - cd /root/GitlabRunner/repo/
# - ls
# - rm -rf ./spring-ci-advanced
# - git config --global user.name 'truongbb96'
# - git config --global user.email 'truongbb@itsol.vn'
# - git clone https://truongbb96:hoanghuynh0801@git.myitsol.com/truongbb96/spring-ci-advanced.git
# - cd ./spring-ci-advanced
- cd /root/GitlabRunner/repo/spring-ci-advanced
- git checkout
- git pull
......@@ -71,14 +66,13 @@ check_quality_gate:
- export QUALITY_GATE=$(./build-test.sh quality-gate)
- echo $QUALITY_GATE
- echo "Sonar statistic result at --> http://192.168.1.210:9000/dashboard?id=spring-ci-advanced"
# force pipeline exit and fail job if QUALITY GATE is FAIL
- sh ./stop_job.sh
- sh ./stop_job.sh # force pipeline exit and fail job if QUALITY GATE is FAIL
dokcer_build:
stage: dokcer_build
only:
- master
# - merge_requestsss
# - merge_request
script:
- cd /root/GitlabRunner/repo/spring-ci-advanced
- ls
......@@ -87,14 +81,36 @@ dokcer_build:
- ./build-test.sh docker-up
- ./build-test.sh docker-push
dokcer_up:
stage: dokcer_up
only:
- master
# - merge_request
script:
- cd /root/GitlabRunner/repo/spring-ci-advanced
- ls
- chmod +x ./build-test.sh
- ./build-test.sh docker-up
- ./build-test.sh docker-push
dokcer_push:
stage: dokcer_push
only:
- master
# - merge_request
script:
- cd /root/GitlabRunner/repo/spring-ci-advanced
- ls
- chmod +x ./build-test.sh
- ./build-test.sh docker-push
send_email:
stage: send_email
only:
- master
- merge_requests
script:
- curl --request POST
--url https://api.sendgrid.com/v3/mail/send
--header 'Authorization:Bearer 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'
--header 'Content-Type:application/json'
--data '{"personalizations":[{"to":[{"email":"truongbb96@gmail.com"}]}],"from":{"email":"truongbb@itsol.vn"},"subject":"CI pipeline result","content":[{"type":"text/plain","value":"CI pipeline done!"}]}'
\ No newline at end of file
- cd /root/GitlabRunner/repo/spring-ci-advanced
- ls
- chmod +x ./build-test.sh
- ./build-test.sh send-email
\ No newline at end of file
......@@ -14,6 +14,7 @@ sub_help(){
echo " quality-gate Check quality gate"
echo " docker-build Build project with docker"
echo " docker-up Start services via docker"
echo " docker-push Push image to Nexus repository via docker"
echo " send-email Send email after stage/pipeline"
echo ""
echo "For help with each sub-command run:"
......@@ -22,13 +23,14 @@ sub_help(){
}
sub_checkout(){
# cd /root/GitlabRunner/repo/
# ls
# rm -rf ./spring-ci-advanced
# git config --global user.name 'truongbb96'
# git config --global user.email 'truongbb@itsol.vn'
# git clone https://truongbb96:hoanghuynh0801@git.myitsol.com/truongbb96/spring-ci-advanced.git
# cd ./spring-ci-advanced
# -------------CLONE-----------------
# cd /root/GitlabRunner/repo/
# rm -rf ./spring-ci-advanced
# git config --global user.name 'truongbb96'
# git config --global user.email 'truongbb@itsol.vn'
# git clone https://truongbb96:hoanghuynh0801@git.myitsol.com/truongbb96/spring-ci-advanced.git
# cd ./spring-ci-advanced
# ------------PULL----------------
cd /root/GitlabRunner/repo/spring-ci-advanced
git checkout
git pull
......@@ -54,10 +56,10 @@ sub_quality-gate(){
if [[ ${qualityGateStatus} != "OK" ]]
then
# echo "*******QUALITY GATE FAILED!**********"
echo 0
echo "NOK"
else
# echo "*******QUALITY GATE PASSED!**********"
echo 1
echo "OK"
fi
}
......@@ -85,12 +87,23 @@ sub_docker-up(){
}
sub_docker-push(){
if [[ -d 'commons/target' ]]
then
echo "Already packaged!"
else
echo "Need to package before building with docker-compose.."
sub_package
fi
#docker push 192.168.1.204:8082/spring-ci-advanced/dev/spring-ci-advanced:latest
docker-compose -f deploy/docker-compose.yml push
}
sub_send-email(){
echo "TODO - send email"
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header 'Authorization:Bearer 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' \
--header 'Content-Type:application/json' \
--data '{"personalizations":[{"to":[{"email":"truongbb96@gmail.com"}]}],"from":{"email":"truongbb@itsol.vn"},"subject":"CI pipeline result","content":[{"type":"text/plain","value":"CI pipeline done!"}]}'
}
_docker_mvn() {
......@@ -99,7 +112,7 @@ _docker_mvn() {
-v "$HOME/.m2:/root/.m2" \
-w /usr/src/ \
maven:3.6.1-jdk-11 \
mvn -U clean $@
mvn --settings settings.xml -U clean $@
}
sub_package() {
......
......@@ -16,4 +16,12 @@
</properties>
</profile>
</profiles>
<mirrors>
<mirror>
<id>ITSOL</id>
<name>ITSOL JSC</name>
<url>http://http://192.168.1.204:8081/maven</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
\ No newline at end of file
......@@ -5,6 +5,7 @@
if [[ $QUALITY_GATE = 0 ]]
then
echo "QUALITY GATE FAILED. CHECK SONAR SCANNER RESULT!"
export QUALITY_GATE="OK"
exit -1
else
echo "QUALITY GATE PASSED. SONAR SCANNER'S SUCCESSFUL!"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment