-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
59 lines (57 loc) · 2.15 KB
/
Jenkinsfile
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
def remote = [:]
remote.name = "EC2 instance"
remote.allowAnyHosts = true
// create credential in Jenkins for EC2 container with id of AWS-EC2 using private key for the container
node {
currentBuild.result = "SUCCESS"
try {
stage("Checkout") {
// cleanWs()
checkout scm
}
withCredentials([file(credentialsId: 'wordle-env-file', variable: 'ENV_FILE_PATH'), file(credentialsId: 'redis-conf-file', variable: 'REDIS_CONF_FILE_PATH'), string(credentialsId: 'redis-secret', variable: 'REDIS_SECRET')]) {
stage("Set up env") {
sh 'chmod u+x -R ./jenkins-docker'
sh './jenkins-docker/Pre-Build/setup-env.sh'
}
}
stage("Build") {
sh './jenkins-docker/Jenkins-build/build.sh'
}
withCredentials([string(credentialsId: 'redis-secret', variable: 'REDIS_SECRET')]) {
stage("Test") {
sh './jenkins-docker/Test/run-test.sh'
}
}
withCredentials([sshUserPrivateKey(credentialsId: 'AWS-EC2', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'username')]) {
remote.host = "52.8.24.164"
// remote.host = IP_ADDRESS
remote.user = username
remote.identityFile = identity
stage("Deploy") {
sshScript remote: remote, script: './jenkins-docker/Deploy/clone-checkout.sh'
sshPut remote: remote, from: './.env', into: '/home/ubuntu/wordle/', override: true
sshPut remote: remote, from: './app/services/Redis/redis.conf', into: '/home/ubuntu/wordle/app/services/Redis/', override: true
sshCommand remote: remote, command: "cd /home/ubuntu/wordle && chmod +x ./bin/server-init.sh && sudo ./bin/server-init.sh"
}
}
}
catch (err) {
currentBuild.result = "FAILURE"
// mail body: "project build error is here: ${env.BUILD_URL}" ,
// from: '[email protected]',
// replyTo: '[email protected]',
// subject: 'project build failed',
// to: '[email protected]'
}
finally {
if (currentBuild.result == 'FAILURE') {
echo 'BUILD FAILED'
}
if (currentBuild.result == 'SUCCESS') {
echo 'BUILD SUCEEDED'
}
// ALWAYS
sh './jenkins-docker/Post/post.sh'
}
}