-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
73 lines (73 loc) · 2.64 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
pipeline {
agent none
stages {
stage ('Info') {
agent any
steps {
echo 'FETCHING JENKINSFILE FROM ${GIT_URL} : ${GIT_BRANCH}'
echo 'BUILD_VERSION: ${BUILD_NUMBER}'
slackSend message:"Build Started - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
}
}
stage('Build Node Application') {
agent {
docker {
image 'node:latest'
}
}
environment {
HOME = '.'
}
steps {
echo 'NPM Build Application ...'
sh "npm install --prefix ./proj1 && npm run build --prod --prefix ./proj1"
}
}
stage('Build Docker Image') {
agent any
steps {
echo 'Build docker image'
sh "docker build -t test ./proj1/"
sh "docker tag test:latest 626379456089.dkr.ecr.ap-southeast-2.amazonaws.com/test:${BUILD_NUMBER}"
}
}
stage('Push to ECR') {
agent any
steps {
script {
docker.withRegistry("https://626379456089.dkr.ecr.ap-southeast-2.amazonaws.com", "ecr:ap-southeast-2:test-ecr-credentials")
{
docker.image("626379456089.dkr.ecr.ap-southeast-2.amazonaws.com/test:${BUILD_NUMBER}").push()
}
}
}
}
stage('Deploy to ECS') {
agent any
steps {
input 'Does everything look OK?'
milestone(1)
sh 'chmod +x ecs-deploy.sh'
sh './ecs-deploy.sh'
}
}
}
post {
always {
script {
if ( currentBuild.currentResult == "SUCCESS" ) {
slackSend color: "good", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was successful"
}
else if( currentBuild.currentResult == "FAILURE" ) {
slackSend color: "danger", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was failed"
}
else if( currentBuild.currentResult == "UNSTABLE" ) {
slackSend color: "warning", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was unstable"
}
else {
slackSend color: "danger", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} its resulat was unclear"
}
}
}
}
}