forked from IbrahimAdell/pipeline-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
54 lines (45 loc) · 1.35 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
pipeline {
agent any
environment {
dockerHubCredentialsID = 'DockerHub' // DockerHub credentials ID.
imageName = 'alikhames/nti-app' // DockerHub repo/image name.
}
stages {
stage('Test') {
steps {
script {
echo "Running Unit Test..."
sh 'chmod 744 gradlew'
sh './gradlew clean test'
}
}
}
stage('Build Docker Image') {
steps {
script {
echo "Building docker image ..."
sh "docker build -t ${imageName}:${BUILD_NUMBER} ."
}
}
}
stage('push Docker Image') {
steps {
script {
echo "pushing docker image ..."
withCredentials([usernamePassword(credentialsId: "${dockerHubCredentialsID}", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){
sh "docker login -u ${USERNAME} -p ${PASSWORD}"
}
sh "docker push ${imageName}:${BUILD_NUMBER}"
}
}
}
}
post {
success {
echo "${JOB_NAME}-${BUILD_NUMBER} pipeline succeeded"
}
failure {
echo "${JOB_NAME}-${BUILD_NUMBER} pipeline failed"
}
}
}