-
Notifications
You must be signed in to change notification settings - Fork 14
/
Jenkinsfile
76 lines (63 loc) · 3.14 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
74
75
76
def CONTAINER_NAME="people-api-pipeline"
def CONTAINER_TAG="latest"
def CONTAINER_DB_NAME="people-api-db-pipeline"
def CONTAINER_DB_TAG="latest"
def OPENSHIFT_PROJECT_NAME="people-api-pipeline"
def OPENSHIFT_IP="docker-registry-default.apps.192.168.1.54.nip.io"
node {
stage('Checkout') {
checkout scm
}
stage("Compile Source"){
try {
bat "\"C:\\Program Files\\dotnet\\dotnet\" restore"
//bat "\"C:\\Program Files\\dotnet\\dotnet\" sonarscanner begin /k:\"peopleapi\" /d:sonar.login=\"1d62160d545c0bd72ec48737ba46219a9d0ea4bb\" /d:sonar.host.url=\"http://localhost:9000\""
bat "\"C:\\Program Files\\dotnet\\dotnet\" build"
//bat "\"C:\\Program Files\\dotnet\\dotnet\" sonarscanner end /d:sonar.login=\"1d62160d545c0bd72ec48737ba46219a9d0ea4bb\""
} catch(error){
echo "The .NET Core 2.x compile failed with ${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('Aqua MicroScanner for DB Image'){
aquaMicroscanner imageName: CONTAINER_DB_NAME, notCompliesCmd: 'exit 1', onDisallowed: 'fail'
}
stage('Aqua MicroScanner for App Image'){
aquaMicroscanner imageName: CONTAINER_NAME, notCompliesCmd: 'exit 1', onDisallowed: 'fail'
}
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 $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"
}