-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJenkinsfile
More file actions
61 lines (50 loc) · 1.47 KB
/
Jenkinsfile
File metadata and controls
61 lines (50 loc) · 1.47 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
def CONTAINER_NAME="sliconf-micro"
def DOCKER_HUB_USER="kodcu"
def HTTP_PORT="8090"
node {
stage('Initialize'){
def dockerHome = tool 'myDocker'
def mavenHome = tool 'myMaven'
env.PATH = "${dockerHome}/bin:${mavenHome}/bin:${env.PATH}"
}
stage('Checkout') {
checkout scm
}
stage('Build'){
sh "mvn clean install"
}
stage('Sonar'){
try {
sh "mvn sonar:sonar"
} catch(error){
echo "Sonar caught: ${error}"
}
}
stage("Image Prune"){
imagePrune(CONTAINER_NAME)
}
stage('Image Build'){
imageBuild(CONTAINER_NAME)
}
stage('Push to Docker Registry'){
withCredentials([usernamePassword(credentialsId: 'dockerHubKodcuAccount', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
pushToImage(CONTAINER_NAME, USERNAME, PASSWORD)
}
}
}
def imagePrune(containerName){
try {
sh "docker image prune -f"
sh "docker stop $containerName"
} catch(error){}
}
def imageBuild(containerName){
sh "docker build -t $containerName:latest -t $containerName --pull --no-cache ."
echo "Image build complete"
}
def pushToImage(containerName, dockerUser, dockerPassword){
sh "docker login -u $dockerUser -p $dockerPassword"
sh "docker tag $containerName:latest $dockerUser/$containerName:latest"
sh "docker push $dockerUser/$containerName:latest"
echo "Image push complete"
}