-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
118 lines (116 loc) · 5.17 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
pipeline {
agent any
environment {
GIT = credentials('rancher')
}
stages {
stage('Build Java App') {
steps {
echo 'Running build automation'
sh './gradlew build --no-daemon'
archiveArtifacts artifacts: 'dist/trainSchedule.zip'
}
}
stage('Create Docker Image') {
when {
branch 'master'
}
steps {
script {
app = docker.build("darkwunan/train-schedule")
app.inside {
sh 'echo $(curl localhost:8080)'
}
}
}
}
stage('Push Docker Image to Repository') {
when {
branch 'master'
}
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
}
}
}
}
/*stage('Neuvector Scan registry') {
when {
branch 'master'
}
steps {
neuvector registrySelection: 'darkwunan', repository: 'darkwunan/train-schedule', scanTimeout: 10, tag: 'latest'
}
}*/
stage('Neuvector Scan image') {
when {
branch 'master'
}
steps {
neuvector nameOfVulnerabilityToExemptFour: '', nameOfVulnerabilityToExemptOne: '', nameOfVulnerabilityToExemptThree: '', nameOfVulnerabilityToExemptTwo: '', nameOfVulnerabilityToFailFour: '', nameOfVulnerabilityToFailOne: '', nameOfVulnerabilityToFailThree: '', nameOfVulnerabilityToFailTwo: '', numberOfHighSeverityToFail: '100', numberOfMediumSeverityToFail: '100', registrySelection: 'darkwunan', repository: 'darkwunan/train-schedule', scanLayers: true, scanTimeout: 10, tag: 'latest'
}
}
stage('Approval for Staging Env Deployment') {
when {
branch 'master'
}
steps {
input 'Deploy to Staging Environment?'
//milestone(1)
}
}
stage('Deploy To Staging') {
when {
branch 'master'
}
steps {
withCredentials([usernamePassword(credentialsId: 'webserver_login', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) {
script {
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no [email protected] \"docker pull darkwunan/train-schedule:${env.BUILD_NUMBER}\""
/*sh "ssh -o StrictHostKeyChecking=no -i /home/centos/jenkin.cer [email protected] \"docker pull darkwunan/train-schedule:${env.BUILD_NUMBER}\""*/
try {
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no [email protected] \"docker stop train-schedule\""
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no [email protected] \"docker rm train-schedule\""
/*sh "ssh -o StrictHostKeyChecking=no -i /home/centos/jenkin.cer [email protected] \"docker stop train-schedule\""
sh "ssh -o StrictHostKeyChecking=no -i /home/centos/jenkin.cer [email protected] \"docker rm train-schedule\""*/
} catch (err) {
echo: 'caught error: $err'
}
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no [email protected] \"docker run --restart always --name train-schedule -p 8080:8080 -d darkwunan/train-schedule:${env.BUILD_NUMBER}\""
/*sh "sssh -o StrictHostKeyChecking=no -i /home/centos/jenkin.cer [email protected] \"docker run --restart always --name train-schedule -p 8080:8080 -d darkwunan/train-schedule:${env.BUILD_NUMBER}\""*/
}
}
}
}
stage('Application Smoke/Sanity Test') {
when {
branch 'master'
}
steps {
input 'Deploy to Production Environment?'
}
}
stage('Push Apps Image to Rancher GitOps') {
when {
branch 'master'
}
steps {
sh """
git clone https://github.com/szulkifli-suse/fleet-examples.git --branch=master /tmp/built_${env.BUILD_NUMBER}
cd /tmp/built_${env.BUILD_NUMBER}/simple/
sed -i "s/train-schedule:[0-9][0-9]/train-schedule:${env.BUILD_NUMBER}/g" frontend-deployment.yaml
cat frontend-deployment.yaml
git add .
git commit -m "Commit new changes"
echo "Check what is GIT"
echo $GIT
git remote set-url origin https://[email protected]/szulkifli-suse/fleet-examples.git
git push origin master
"""
}
}
}
}