-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
73 lines (61 loc) · 2.64 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def CONTAINER_NAME="client-api-pipeline"
def CONTAINER_TAG="latest"
def CONTAINER_DB_NAME="client-api-db-pipeline"
def CONTAINER_DB_TAG="latest"
def OPENSHIFT_PROJECT_NAME="client-api-pipeline"
def OPENSHIFT_IP="172.30.1.1:5000"
node {
stage('Checkout') {
checkout scm
}
stage("Compile Source"){
try {
bat "buildapp.cmd"
} catch(error){
echo "The go compile failed with ${error}"
}
}
stage('SonarQube'){
try {
bat "c:\\projects\\sonar-scanner\\bin\\sonar-scanner -Dsonar.projectKey=clientapi -Dsonar.sources=."
} catch(error){
echo "The sonar server could not be reached: ${error}"
}
}
stage("Image Prune"){
imagePrune(CONTAINER_NAME)
imagePrune(CONTAINER_DB_NAME)
}
stage('DB Image Build'){
imageBuild(CONTAINER_DB_NAME, CONTAINER_DB_TAG, "database\\")
}
stage('Application Image Build'){
imageBuild(CONTAINER_NAME, CONTAINER_TAG, ".")
}
stage('Push DB to OpenShift Registry'){
withCredentials([usernamePassword(credentialsId: 'openshift-docker-registry-account', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
pushToImage(OPENSHIFT_IP,OPENSHIFT_PROJECT_NAME, CONTAINER_DB_NAME, CONTAINER_DB_TAG, USERNAME, PASSWORD)
}
}
stage('Push App to OpenShift Registry'){
withCredentials([usernamePassword(credentialsId: 'openshift-docker-registry-account', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
pushToImage(OPENSHIFT_IP,OPENSHIFT_PROJECT_NAME, CONTAINER_NAME, CONTAINER_TAG, USERNAME, PASSWORD)
}
}
}
def imagePrune(containerName){
try {
bat "\"C:\\Program Files\\Docker\\Docker\\Resources\\bin\\docker\" image prune -f"
bat "\"C:\\Program Files\\Docker\\Docker\\Resources\\bin\\docker\" stop $containerName"
} catch(error){}
}
def imageBuild(containerName, tag, pathToDockerfile){
bat "\"C:\\Program Files\\Docker\\Docker\\Resources\\bin\\docker\" build -t $containerName:$tag --pull --no-cache $pathToDockerfile"
echo "Image build complete"
}
def pushToImage(openshiftIP, projectName, containerName, tag, dockerUser, dockerPassword){
bat "\"C:\\Program Files\\Docker\\Docker\\Resources\\bin\\docker\" login -u $dockerUser -p $dockerPassword $openshiftIP"
bat "\"C:\\Program Files\\Docker\\Docker\\Resources\\bin\\docker\" tag $containerName:$tag $openshiftIP/$projectName/$containerName:$tag"
bat "\"C:\\Program Files\\Docker\\Docker\\Resources\\bin\\docker\" push $openshiftIP/$projectName/$containerName:$tag"
echo "Image push complete to OpenShift"
}