Skip to content

Commit 7082367

Browse files
authored
Create Jenkinsfile
1 parent ee95a5e commit 7082367

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

Jenkinsfile

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// Define Application name
2+
def APPNAME = "freecodecamp"
3+
4+
// Define which branch build and deploy need to run in the below array
5+
def branchfilter = ['dev', 'prod']
6+
7+
if (!branchfilter.contains(env.BRANCH_NAME)) {
8+
println 'Now is not the time to run the pipeline.'
9+
println 'Exiting without running subsequent stages.'
10+
println env.BRANCH_NAME
11+
currentBuild.result = 'SUCCESS'
12+
return
13+
}
14+
15+
// Define dev-specific vars
16+
if (env.BRANCH_NAME == 'dev') {
17+
DEPLOY_ENV = 'DEV'
18+
LOGICAL_ENV = 'dev'
19+
IS_BUILD = true
20+
IS_DEPLOY = true
21+
IS_APP_DEPLOY = true
22+
IS_API_DEPLOY = true
23+
ENABLE_CACHE = false
24+
}
25+
26+
// Define prod-specific vars
27+
if (env.BRANCH_NAME == 'prod') {
28+
DEPLOY_ENV = 'PROD'
29+
LOGICAL_ENV = 'prod'
30+
IS_BUILD = true
31+
IS_DEPLOY = true
32+
IS_APP_DEPLOY = true
33+
IS_API_DEPLOY = true
34+
ENABLE_CACHE = true
35+
}
36+
37+
pipeline {
38+
agent {
39+
label 'tc-ecs-agent-large'
40+
}
41+
42+
environment {
43+
CI_AUTH0_URL = credentials('CI_AUTH0_URL')
44+
CI_AUTH0_CLIENTID = credentials('CI_AUTH0_CLIENTID')
45+
CI_AUTH0_CLIENTSECRET = credentials('CI_AUTH0_CLIENTSECRET')
46+
CI_AUTH0_AUDIENCE = credentials('CI_AUTH0_AUDIENCE')
47+
}
48+
49+
options { skipDefaultCheckout() }
50+
51+
stages
52+
{
53+
stage('checkout')
54+
{
55+
steps {
56+
//cheking out code
57+
checkout scm
58+
script {
59+
giturltoken = scm.getUserRemoteConfigs()[0].getUrl().tokenize('/')
60+
env.TC_GIT_ORG = giturltoken.get(giturltoken.size()-2)
61+
env.TC_REPONAME = scm.getUserRemoteConfigs()[0].getUrl().tokenize('/').last().split("\\.")[0]
62+
env.TC_GIT_COMMIT_MSG = sh (script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true).trim()
63+
env.TC_GIT_AUTHOR = sh (script: 'git log -1 --pretty=%an ${GIT_COMMIT}', returnStdout: true).trim()
64+
env.TC_GIT_HASH = sh (script: 'git log -1 --pretty=%h ${GIT_COMMIT}', returnStdout: true).trim()
65+
if (sh(script: "git log -1 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]'", returnStatus: true) == 0) {
66+
currentBuild.result = 'NOT_BUILT'
67+
error 'Aborting because commit message contains [skip ci]'
68+
}
69+
}
70+
}
71+
72+
}
73+
stage('pre-req install')
74+
{
75+
steps {
76+
//Installing required pre-req software
77+
sh '''
78+
#!/bin/bash
79+
apt update -y
80+
apt install awscli jq curl sudo -y
81+
curl https://get.docker.com/ > dockerinstall && chmod 777 dockerinstall && ./dockerinstall
82+
git clone --branch dev-jenkins https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
83+
cp ./../buildscript/master_deploy.sh .
84+
cp ./../buildscript/buildenv.sh .
85+
cp ./../buildscript/awsconfiguration.sh .
86+
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
87+
apt -y install nodejs
88+
'''
89+
}
90+
}
91+
stage('fetching configuration')
92+
{
93+
steps {
94+
//fetching pre-req
95+
sh """
96+
#!/bin/bash
97+
./awsconfiguration.sh ${DEPLOY_ENV}
98+
echo "Fetching deployvar"
99+
./buildenv.sh -e ${DEPLOY_ENV} -b ${LOGICAL_ENV}-${APPNAME}-deployvarj
100+
mv buildenvvar deployenvvar
101+
mv buildenvvarg deployenvvarg
102+
echo "Fetching Buildvar"
103+
./buildenv.sh -e ${DEPLOY_ENV} -b ${LOGICAL_ENV}-${APPNAME}-buildvar
104+
aws s3 cp s3://tc-platform-${LOGICAL_ENV}/securitymanager/${LOGICAL_ENV}-freecodecamp.env ./.env
105+
"""
106+
load 'awsenvconfg'
107+
load 'deployenvvarg'
108+
load 'buildenvvarg'
109+
}
110+
}
111+
stage('build application')
112+
{
113+
//Building Application
114+
when { expression { IS_BUILD } }
115+
steps {
116+
// Doing Build
117+
sh """
118+
#!/bin/bash
119+
node --version
120+
npm --version
121+
git config --global url."https://git@".insteadOf git://
122+
npm ci
123+
npm run build
124+
ls -lath
125+
"""
126+
}
127+
}
128+
stage('appdeploy')
129+
{
130+
//Deploying app
131+
when { expression { IS_APP_DEPLOY } }
132+
steps {
133+
//Doing Deployment
134+
echo "Deploying application"
135+
//input(message: 'Hello World!', ok: 'Submit')
136+
sh """
137+
#!/bin/bash
138+
./master_deploy.sh -d CFRONT -e $DEPLOY_ENV -c $ENABLE_CACHE
139+
"""
140+
}
141+
}
142+
stage('apideploy')
143+
{
144+
//Deploying app
145+
when { expression { IS_API_DEPLOY } }
146+
steps {
147+
//Doing Deployment
148+
echo "Deploying Api"
149+
// input(message: 'Hello World!', ok: 'Submit')
150+
sh """
151+
#!/bin/bash
152+
sed -i '/node_modules/d' ./.dockerignore
153+
docker build -f docker/api/ECSDockerfile -t $APPNAME-api:latest .
154+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}-api
155+
"""
156+
}
157+
}
158+
}
159+
160+
}

0 commit comments

Comments
 (0)