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