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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
#!/usr/bin/env groovy
properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
[$class: 'hudson.model.StringParameterDefinition', name: 'PHASE', defaultValue: "BUILD_DEPLOY"],
[$class: 'hudson.model.StringParameterDefinition', name: 'TARGET_ENV', defaultValue: "DEV"],
[$class: 'hudson.model.StringParameterDefinition', name: 'K8S_CLUSTER_URL',defaultValue: "https://k8s.onap.org"],
[$class: 'hudson.model.StringParameterDefinition', name: 'K8S_CONTEXT',defaultValue: "default"],
[$class: 'hudson.model.StringParameterDefinition', name: 'K8S_USERNAME',defaultValue: "root"],
[$class: 'hudson.model.PasswordParameterDefinition', name: 'K8S_PASSWORD',defaultValue: "k8s_password"],
[$class: 'hudson.model.PasswordParameterDefinition', name: 'K8S_TOKEN',defaultValue: "k8suser@fgps.onap.org:enc:dfxissWKLGRuldTwXuAuK-WAT-b-f-wS"],
[$class: 'hudson.model.StringParameterDefinition', name: 'K8S_NAME',defaultValue: "DEV"],
[$class: 'hudson.model.StringParameterDefinition', name: 'K8S_PODS_REPLICAS',defaultValue: "1"],
[$class: 'hudson.model.StringParameterDefinition', name: 'K8S_SERVICE_ACCOUNT',defaultValue: "default"],
[$class: 'hudson.model.BooleanParameterDefinition', name: 'USE_ROOT_NS',defaultValue: false],
[$class: 'hudson.model.StringParameterDefinition', name: 'BROKER_URL',defaultValue: "http://broker.onap.org:30120"],
[$class: 'hudson.model.StringParameterDefinition', name: 'PACT_USERNAME', defaultValue: "pactadmin"],
[$class: 'hudson.model.PasswordParameterDefinition', name: 'PACT_PASSWORD', defaultValue: "pactadmin"],
[$class: 'hudson.model.StringParameterDefinition', name: 'CONSUMER', defaultValue: ""],
[$class: 'hudson.model.StringParameterDefinition', name: 'GIT_REPO_FOLDER',defaultValue: ""],
[$class: 'hudson.model.StringParameterDefinition', name: 'DEV_TEST_GIT_APP',defaultValue: ""],
[$class: 'hudson.model.StringParameterDefinition', name: 'DEV_TEST_SERVER_URL',defaultValue: ""],
[$class: 'hudson.model.StringParameterDefinition', name: 'LISA_PATH', defaultValue: "/opt/app/workload/tools/itko/server/9.5.1/Projects/"],
[$class: 'hudson.model.StringParameterDefinition', name: 'TEST_CASE_PATH',defaultValue: "/Tests/HelloTest.tst"],
[$class: 'hudson.model.StringParameterDefinition', name: 'SUITE_CASE_PATH', defaultValue: "/Tests/Suites/AllTestsSuite.ste"],
[$class: 'hudson.model.StringParameterDefinition', name: 'CONFIG_PATH', defaultValue: "/Configs/project.config"],
[$class: 'hudson.model.StringParameterDefinition', name: 'STAGING_DOC_PATH',defaultValue: "/Tests/StagingDocs/Run1User1Cycle.stg"],
[$class: 'hudson.model.StringParameterDefinition', name: 'ANS_ROLE',defaultValue: ""],
[$class: 'hudson.model.StringParameterDefinition', name: 'ANS_INVENTORY',defaultValue: "inventory/dev/hosts"],
[$class: 'hudson.model.StringParameterDefinition', name: 'GITPlaybookPATH', defaultValue: ""],
[$class: 'hudson.model.StringParameterDefinition', name: 'GITConfigRolePATH', defaultValue: ""],
[$class: 'hudson.model.StringParameterDefinition', name: 'SONAR_BREAKER_SKIP',defaultValue: "True"],
[$class: 'hudson.model.StringParameterDefinition', name: 'SONAR_BREAKER_QRY_INTERVAL',defaultValue: "7000"],
[$class: 'hudson.model.StringParameterDefinition', name: 'SONAR_BREAKER_QRY_MAXATTEMPTS',defaultValue: "100"],
[$class: 'hudson.model.StringParameterDefinition', name: 'ECO_PIPELINE_ID',defaultValue: ""],
[$class: 'hudson.model.StringParameterDefinition', name: 'BUILD_VERSION',defaultValue: ""]
]]])
/**
jdk1.8 = fixed name for java
M3 = fixed name for maven
general_maven_settings = fixed name for maven settings Jenkins managed file
*/
echo "Build branch: ${env.BRANCH_NAME}"
node("docker") {
stage 'Checkout'
checkout scm
pom = readMavenPom file: 'pom.xml'
PROJECT_NAME = pom.properties['namespace'] + ":" + pom.artifactId;
// env.SERVICE_NAME=pom.artifactId;
env.APP_NAME=pom.artifactId;
env.SERVICE_NAME=pom.properties['serviceArtifactName']
env.VERSION=pom.version;
env.ANS_ROLE=SERVICE_NAME+"_configrole"
env.BUILDNUMBER_TIMESTAMP="${BUILD_NUMBER}"+"-"+"${currentBuild.timeInMillis}"
echo "ANS_ROLE: ${ANS_ROLE}"
LABEL_VERSION=pom.version.replaceAll(".", "-");
echo "LabelVerion: " + LABEL_VERSION
NAMESPACE=pom.properties['namespace']
TARGET_ENV=TARGET_ENV.toLowerCase()
if(params.USE_ROOT_NS)
{
env.KUBE_NAMESPACE=pom.properties['kube.namespace']
}else{
env.KUBE_NAMESPACE=pom.properties['kube.namespace']+"-"+TARGET_ENV
}
if(TARGET_ENV!="dev"){
env.ANS_INVENTORY="inventory/"+TARGET_ENV+"/hosts"
echo "ANS_INVENTORY: ${ANS_INVENTORY}"
}
env.TARGET_ENV=TARGET_ENV
REPLICA_COUNT="${params.K8S_PODS_REPLICAS}"
env.IMAGE_NAME=pom.properties['docker.registry']+"/"+NAMESPACE+"/"+SERVICE_NAME+":latest"
if (env.TARGET_ENV == "prod") {
env.IMAGE_NAME=pom.properties['docker.registry']+"/"+NAMESPACE+"/"+SERVICE_NAME+":release"
}
echo "Artifact: " + PROJECT_NAME
env.DOCKER_HOST="tcp://localhost:4243"
env.DOCKER_CONFIG="${WORKSPACE}/.docker"
def branchName
//This value can ideally come from pom as in IMAGE_NAME
def dockerRegistry = "nexus.onap.org:5100"
if(params.BUILD_VERSION != "")
{
echo "BUILD VERSION Set : " + BUILD_VERSION
currentBuild.displayName = "VERSION-${BUILD_VERSION}"
currentBuild.description = "${BUILD_VERSION} ${ECO_PIPELINE_ID} ${PHASE}"
}else{
echo "BUILD VERSION Not Set, Use pom version: " + VERSION
currentBuild.displayName = "VERSION-" +VERSION
currentBuild.description = "${VERSION} ${ECO_PIPELINE_ID} ${PHASE}"
}
env.KUBECTL_OPTS="--server=${K8S_CLUSTER_URL} --insecure-skip-tls-verify=true --password=${K8S_PASSWORD} --username=${K8S_USERNAME}"
env.K8S_SERVER_CREDENTIALS = " k8server=${K8S_CLUSTER_URL}:6443 k8susername=${K8S_USERNAME} k8spassword=${K8S_PASSWORD} k8stoken=${K8S_TOKEN}"
if ("${K8S_TOKEN}" != "" ) {
env.KUBECTL_OPTS = "--server=${K8S_CLUSTER_URL} --insecure-skip-tls-verify=true --token=${K8S_TOKEN}"
env.K8S_SERVER_CREDENTIALS =" k8server=${K8S_CLUSTER_URL}:6443 k8susername= k8spassword= k8stoken=${K8S_TOKEN}"
}
//echo "env.KUBECTL_OPTS=${KUBECTL_OPTS}"
//echo "K8S_SERVER_CREDENTIALS=${K8S_SERVER_CREDENTIALS}"
//IST Variable
LISA_PATH_NEW="${LISA_PATH}"+SERVICE_NAME
// Create kubectl.conf file here from Pipeline properties provided.
withEnv(["PATH=${env.PATH}:${tool 'M3'}/bin:${tool 'jdk1.8'}/bin", "JAVA_HOME=${tool 'jdk1.8'}", "MAVEN_HOME=${tool 'M3'}"]) {
echo "JAVA_HOME=${env.JAVA_HOME}"
echo "MAVEN_HOME=${env.MAVEN_HOME}"
echo "PATH=${env.PATH}"
wrap([$class: 'ConfigFileBuildWrapper', managedFiles: [
[fileId: 'maven-settings.xml', variable: 'MAVEN_SETTINGS'],
[fileId: 'sonar-secret.txt', variable: 'SONAR_SECRET'],
[fileId: 'sonar.properties', variable: 'SONAR_PROPERTIES']
]]) {
branchName = (env.BRANCH_NAME ?: "master").replaceAll(/[^0-9a-zA-Z_]/, "-")
if ("${PHASE}" == "BUILD" || "${PHASE}" == "BUILD_DEPLOY" ) {
stage 'Compile'
sh 'mvn -DskipTests -Dmaven.test.skip=true -s $MAVEN_SETTINGS -Ddummy.prop=$SONAR_PROPERTIES clean compile'
stage 'Unit Test'
sh 'mvn -s $MAVEN_SETTINGS verify -P all-tests'
stage 'Package'
sh 'mvn -DskipTests -Dmaven.test.skip=true -s $MAVEN_SETTINGS package'
stage 'Verify'
sh 'mvn -DskipTests -Dmaven.test.skip=true -s $MAVEN_SETTINGS verify'
if ("${DEV_TEST_GIT_APP}" != "") {
stage("CADev Repo Update") {
def GitinvokeURL = "${DEV_TEST_GIT_APP}/gitapp/service/git/push?gitUrl=${GIT_REPO_FOLDER}/${SERVICE_NAME}"
sh "curl -i -X GET \'${GitinvokeURL}\'"
}
stage("Component Test Using CA DEV TEST") {
def invokeURL = "${DEV_TEST_SERVER_URL}/lisa-invoke/runTest?testCasePath=${LISA_PATH_NEW}${TEST_CASE_PATH}&stagingDocPath=${LISA_PATH_NEW}${STAGING_DOC_PATH}"
sh "curl -i \'${invokeURL}\'"
invokeURL = "${DEV_TEST_SERVER_URL}/lisa-invoke/runSuite?suitePath=${LISA_PATH_NEW}${SUITE_CASE_PATH}&configPath=${LISA_PATH_NEW}${CONFIG_PATH}"
sh "curl -i \'${invokeURL}\'"
}
}
stage 'Component Test Using Mockito'
sh 'mvn -s $MAVEN_SETTINGS -Dtest=ITComponentTest test'
stage 'Publish Artifact'
//sh 'docker ps'
sh 'mvn -DskipTests -Dmaven.test.skip=true -Dhttps.protocols="TLSv1" -Djavax.net.ssl.trustStore="/opt/app/etc/cacerts.jks" -Djavax.net.ssl.trustStorePassword="password" -Djavax.net.ssl.keyStore="/opt/app/etc/cacerts.jks" -Djavax.net.ssl.keyStorePassword="password" -s $MAVEN_SETTINGS -U docker:build docker:push'
}
if ("${PHASE}" == "BUILD_DEPLOY" || "${PHASE}" == "DEPLOY" || "${PHASE}" == "CONFIG") {
// deploy to k8s
stage ('Clone playbook and configrole') {
// read values captured at the generate time
env.REPO_PROJECT = readFile './repoproject.txt'
env.REPO_PROJECT= "${REPO_PROJECT.trim()}"
// put some if conditions to use below values if empty above.
if(params.GITPlaybookPATH==""){
GITPlaybookPATH="https://git.onap.org/scm/"+"${REPO_PROJECT}"+"/"+SERVICE_NAME+"_playbook.git"
}
echo "GITPlaybookPATH: ${GITPlaybookPATH}"
if(params.GITConfigRolePATH==""){
GITConfigRolePATH="https://git.onap.org/scm/"+"${REPO_PROJECT}"+"/"+SERVICE_NAME+"_configrole.git"
}
echo "GITConfigRolePATH: ${GITConfigRolePATH}"
env.dockermechid = readFile './dockerbuilduser.txt'
env.dockermechid = "${dockermechid.trim()}"
env.repogitid = readFile './repogitid.txt'
env.repogitid = "${repogitid.trim()}"
echo "repogitid : ${repogitid}"
withCredentials([usernamePassword(credentialsId: env.repogitid, usernameVariable: 'ITS_SECRET_USERNAME', passwordVariable: 'ITS_SECRET_PASSWORD')]) {
env.DOCKER_HOST='unix:///var/run/docker.sock'
env.ANS_HOST = params.ANS_HOST ?: new URL("${params.K8S_CLUSTER_URL}").getHost()
sh 'rm -rf playbook'
dir('playbook') {
git url: "${GITPlaybookPATH}", credentialsId: "${repogitid}"
}
dir("playbook/roles/${ANS_ROLE}") {
if (branchName != 'master'){
echo "branchName: ${branchName}"
git url: "${GITConfigRolePATH}", credentialsId: "${repogitid}", branch: "${branchName}"
}
else{
echo "else branchName: ${branchName}"
git url: "${GITConfigRolePATH}", credentialsId: "${repogitid}"
}
}
}
}
}
if ( "${PHASE}" == "CONTRACT_GENERATE") {
stage 'Contract Generate Publish and QG2'
sh 'mvn -s $MAVEN_SETTINGS -Dtest=PactTestSuit test -DBROKER_URL=${BROKER_URL} -DuserName=${PACT_USERNAME} -Dpassword=${PACT_PASSWORD}'
sh 'mvn -s $MAVEN_SETTINGS pact:publish -DBROKER_URL=${BROKER_URL} -DuserName=${PACT_USERNAME} -Dpassword=${PACT_PASSWORD}'
}
if ("${PHASE}" == "CONTRACT_VERIFY" ) {
stage ('Contract Verify' ){
withEnv([
"APP_NAME=${SERVICE_NAME}",
"K8S_CTX=${K8S_CONTEXT}",
"APP_NS=${KUBE_NAMESPACE}",
"KUBECTL=/opt/app/kubernetes/v1.5.2/bin/kubectl",
]) {
def CLUSTER_URL=K8S_CLUSTER_URL.substring(8)
NODE_PORT = sh (
script: '${KUBECTL} get service ${APP_NAME} --namespace ${APP_NS} --context ${K8S_CTX} ${KUBECTL_OPTS} --output jsonpath={.spec.ports[*].nodePort}',
returnStdout: true
).trim()
if( "${CONSUMER}" == "") {
sh "mvn -s $MAVEN_SETTINGS pact:verify -DBROKER_URL=${BROKER_URL} -DuserName=${PACT_USERNAME} -Dpassword=${PACT_PASSWORD} -DAPP_URL=${CLUSTER_URL} -DAPP_PORT=${NODE_PORT}"
} else {
sh "mvn -s $MAVEN_SETTINGS pact:verify -Dpact.filter.consumers=${CONSUMER} -DBROKER_URL=${BROKER_URL} -DuserName=${PACT_USERNAME} -Dpassword=${PACT_PASSWORD} -DAPP_URL=${CLUSTER_URL} -DAPP_PORT=${NODE_PORT}"
}
}
}
}
if ("${PHASE}" == "INTEGRATION_TEST" || "${PHASE}" == "IST" || "${PHASE}" == "DEPLOY_IST" ) {
stage("CADev Repo Update") {
def GitinvokeURL = "${DEV_TEST_GIT_APP}/gitapp/service/git/push?gitUrl=${GIT_REPO_FOLDER}/${SERVICE_NAME}"
sh "curl -i -X GET \'${GitinvokeURL}\'"
}
stage("Functional Test") {
def invokeURL = "${DEV_TEST_SERVER_URL}/lisa-invoke/runTest?testCasePath=${LISA_PATH_NEW}${TEST_CASE_PATH}&stagingDocPath=${LISA_PATH_NEW}${STAGING_DOC_PATH}"
sh "curl -i \'${invokeURL}\'"
invokeURL = "${DEV_TEST_SERVER_URL}/lisa-invoke/runSuite?suitePath=${LISA_PATH_NEW}${SUITE_CASE_PATH}&configPath=${LISA_PATH_NEW}${CONFIG_PATH}"
sh "curl -i \'${invokeURL}\'"
}
}
}
}
}
|