-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
75 lines (68 loc) · 2.12 KB
/
Copy pathJenkinsfile
File metadata and controls
75 lines (68 loc) · 2.12 KB
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
74
75
pipeline {
agent any
environment {
GIT_REPO_URL = 'https://github.com/Rapter1990/cryptoexchangeapi.git'
GIT_REPO_ID = 'fdf97c32-ab81-4fff-ae77-8f833263dc55'
BRANCH_NAME = 'main'
DOCKERHUB_USERNAME = 'noyandocker'
DOCKER_IMAGE_NAME = 'cryptoexchangeapi-jenkins'
}
stages {
stage('Checkout') {
steps {
script {
checkout([
$class: 'GitSCM',
branches: [[name: "*/${env.BRANCH_NAME}"]],
userRemoteConfigs: [[
url: "${env.GIT_REPO_URL}",
credentialsId: env.GIT_REPO_ID
]]
])
}
}
}
stage('Build') {
agent {
docker {
image 'maven:3.9.11-amazoncorretto-25-alpine'
}
}
steps {
sh 'mvn clean install'
}
}
stage('Build Docker Image') {
agent {
docker {
image 'docker:27.5.1'
}
}
steps {
sh "docker build -t ${env.DOCKERHUB_USERNAME}/${env.DOCKER_IMAGE_NAME}:latest ."
}
}
stage('Push Docker Image') {
agent {
docker {
image 'docker:27.5.1'
}
}
steps {
withDockerRegistry([credentialsId: 'docker-hub-credentials', url: '']) {
sh "docker push ${env.DOCKERHUB_USERNAME}/${env.DOCKER_IMAGE_NAME}:latest"
}
}
}
}
post {
always {
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true,
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
}
}
}