-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathJenkinsfile
45 lines (37 loc) · 1.06 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
pipeline {
agent any
options{
buildDiscarder(logRotator(numToKeepStr: '5', daysToKeepStr: '5'))
timestamps()
}
environment{
registry = "vkunal/aws-app"
registryCredential = 'dockerhub'
commitHash = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
}
stages {
stage('Build Docker Image') {
steps {
script{
sh "sudo docker build -t ${registry}:${commitHash} ."
}
}
}
stage('Run Docker Container') {
steps {
script{
sh "sudo docker run -dp 3000:3000 ${registry}:${commitHash}"
}
}
}
stage('Push to DockerHub') {
steps {
script{
docker.withRegistry( 'https://index.docker.io/v1/', registryCredential) {
sh "docker push ${registry}:${commitHash}"
}
}
}
}
}
}