-
Notifications
You must be signed in to change notification settings - Fork 16
/
Jenkinsfile
73 lines (62 loc) · 1.57 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 {
label 'group1'
}
tools {
nodejs 'nodejs'
dockerTool 'docker'
}
triggers {
githubPush()
}
environment {
DOCKERHUB_CREDENTIALS = credentials('my_dockerhub_creds')
IMAGE_NAME = 'pavlin117/mynodejsapp'
}
stages {
stage('Clean') {
steps {
cleanWs()
}
}
stage('Clone Repo') {
steps {
git branch: 'main', url: 'https://github.com/stoenpav/nodejs-my-proj.git'
}
}
stage('Build') {
steps {
sh 'npm ci' //This is for building the nodejs project
}
}
stage('Test') {
steps {
sh 'npm test' //This is for testing the nodejs modules
}
}
stage('Docker login'){
steps {
sh 'docker login -u $DOCKERHUB_CREDENTIALS_USR -p $DOCKERHUB_CREDENTIALS_PSW'
}
}
stage('Docker build and tag'){
steps {
sh 'docker build -t ${IMAGE_NAME} -f Dockerfile .'
sh 'docker tag ${IMAGE_NAME} ${IMAGE_NAME}:${BUILD_NUMBER}'
}
}
stage('Docker Push'){
steps {
sh 'docker push ${IMAGE_NAME}:${BUILD_NUMBER}'
}
}
stage('Deploy')
{
steps
{
sh 'docker container rm -f mynodejsapp || true'
sh 'docker container run -d -p 4000:3000 --name mynodejsapp ${IMAGE_NAME}'
}
}
}
}