-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
71 lines (64 loc) · 2.46 KB
/
Jenkinsfile
File metadata and controls
71 lines (64 loc) · 2.46 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
pipeline {
agent any
parameters {
string(name: 'DOCKER_IMAGE', defaultValue: 'your-dockerhub-username/cowrite', description: 'Docker image name')
string(name: 'DOCKER_TAG', defaultValue: "${env.BUILD_NUMBER}", description: 'Docker tag')
string(name: 'REGISTRY_CREDENTIALS', defaultValue: 'docker-hub-credentials', description: 'Registry credentials ID')
string(name: 'SSH_CONFIG', defaultValue: 'your-ssh-config-name', description: 'Jenkins SSH host config')
string(name: 'CONTAINER_NAME', defaultValue: 'cowrite', description: 'Runtime container name')
string(name: 'PORTS', defaultValue: '-p 8080:8080', description: 'Run port mappings')
}
tools {
maven 'Maven3'
jdk 'JDK11'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build with Maven') {
steps {
sh 'mvn clean package -DskipTests'
}
}
stage('Build Docker Image') {
steps {
script {
docker.build("${params.DOCKER_IMAGE}:${params.DOCKER_TAG}")
}
}
}
stage('Push to Registry') {
steps {
script {
docker.withRegistry('', params.REGISTRY_CREDENTIALS) {
docker.image("${params.DOCKER_IMAGE}:${params.DOCKER_TAG}").push()
}
}
}
}
stage('Deploy to Remote Server') {
steps {
sshPublisher(
publishers: [
sshPublisherDesc(
configName: params.SSH_CONFIG,
transfers: [
sshTransfer(
execCommand: """
docker pull ${params.DOCKER_IMAGE}:${params.DOCKER_TAG} &&
docker stop ${params.CONTAINER_NAME} || true &&
docker rm ${params.CONTAINER_NAME} || true &&
docker run -d --name ${params.CONTAINER_NAME} ${params.PORTS} ${params.DOCKER_IMAGE}:${params.DOCKER_TAG}
"""
)
]
)
]
)
}
}
}
}