1 #!/usr/bin/env groovy
\r
3 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
6 # you may not use this file except in compliance with the License. #
\r
7 # You may obtain a copy of the License at #
\r
9 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
11 # Unless required by applicable law or agreed to in writing, software #
\r
12 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
14 # See the License for the specific language governing permissions and #
\r
15 # limitations under the License. #
\r
16 ##############################################################################*/
\r
18 properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
\r
19 [$class: 'hudson.model.StringParameterDefinition', name: 'PHASE', defaultValue: "BUILD"],
\r
20 [$class: 'hudson.model.StringParameterDefinition', name: 'ENV', defaultValue: "dev"],
\r
21 [$class: 'hudson.model.StringParameterDefinition', name: 'MECHID', defaultValue: "username"],
\r
22 [$class: 'hudson.model.StringParameterDefinition', name: 'KUBE_CONFIG', defaultValue: "kubeConfig-dev"],
\r
23 [$class: 'hudson.model.StringParameterDefinition', name: 'OTF_MONGO_DB', defaultValue: "otf_mongo_dev_db"],
\r
24 [$class: 'hudson.model.StringParameterDefinition', name: 'OTF_CAMUNDA_DB', defaultValue: "otf_camunda_dev_db"],
\r
25 [$class: 'hudson.model.StringParameterDefinition', name: 'TILLER_NAMESPACE', defaultValue: "org.oran.otf"]
\r
30 echo "Build branch: ${env.BRANCH_NAME}"
\r
35 PHASES = PHASE.tokenize('_');
\r
36 echo "PHASES : " + PHASES
\r
37 pom = readMavenPom file: 'pom.xml'
\r
38 ARTIFACT_ID = pom.artifactId;
\r
39 VERSION = pom.version;
\r
40 LABEL_VERSION = pom.version.replaceAll("\\.", "-");
\r
41 echo "LabelVerion: " + LABEL_VERSION
\r
42 NAMESPACE = pom.groupId
\r
43 echo "Tiller Namespace: " + TILLER_NAMESPACE
\r
44 DOCKER_REGISTRY = pom.properties['docker.registry']
\r
46 if( ENV.equalsIgnoreCase("dev") ){
\r
47 IMAGE_NAME = pom.properties['docker.registry'] + "/" + NAMESPACE + "/" + ARTIFACT_ID + ":" + VERSION
\r
49 if( ENV.equalsIgnoreCase("prod") || ENV.equalsIgnoreCase("prod-dr") ){
\r
50 IMAGE_NAME = pom.properties['docker.registry'] + "/" + NAMESPACE + ".prod" + "/" + ARTIFACT_ID + ":" + VERSION
\r
53 if( ENV.equalsIgnoreCase("st") ){
\r
54 IMAGE_NAME = pom.properties['docker.registry'] + "/" + NAMESPACE + ".st" + "/" + ARTIFACT_ID + ":" + VERSION
\r
56 echo "Artifact: " + IMAGE_NAME
\r
59 if( ENV.equalsIgnoreCase("dev") ){
\r
60 ROUTER_CONFIG="mysqlRouterConfig-dev.ini"
\r
62 if( ENV.equalsIgnoreCase("st") ){
\r
63 ROUTER_CONFIG="mysqlRouterConfig-st.ini"
\r
65 if( ENV.equalsIgnoreCase("prod") || ENV.equalsIgnoreCase("prod-dr")){
\r
66 ROUTER_CONFIG="mysqlRouterConfig-prod.ini"
\r
69 withEnv(["PATH=${env.PATH}:${tool 'mvn352'}/bin:${tool 'jdk180'}/bin:${env.WORKSPACE}/linux-amd64", "JAVA_HOME=${tool 'jdk180'}", "MAVEN_HOME=${tool 'mvn352'}", "HELM_HOME=${env.WORKSPACE}"]) {
\r
71 echo "JAVA_HOME=${env.JAVA_HOME}"
\r
72 echo "MAVEN_HOME=${env.MAVEN_HOME}"
\r
73 echo "PATH=${env.PATH}"
\r
74 echo "HELM_HOME=${env.HELM_HOME}"
\r
76 wrap([$class: 'ConfigFileBuildWrapper', managedFiles: [
\r
77 [fileId: 'maven-settings.xml', variable: 'MAVEN_SETTINGS'],
\r
78 [fileId: 'maven-settings-security.xml', variable: 'MAVEN_SETTINGS_SECURITY']
\r
82 if (PHASES.contains("BUILD")) {
\r
84 sh 'mvn -s $MAVEN_SETTINGS -Dsettings.security=$MAVEN_SETTINGS_SECURITY clean compile'
\r
87 sh 'mvn -s $MAVEN_SETTINGS -Dsettings.security=$MAVEN_SETTINGS_SECURITY test'
\r
90 sh 'mvn -s $MAVEN_SETTINGS -Dsettings.security=$MAVEN_SETTINGS_SECURITY package'
\r
91 //sh 'mvn -DskipTests -Dmaven.test.skip=true -s $MAVEN_SETTINGS package'
\r
94 sh 'mvn -s $MAVEN_SETTINGS -Dsettings.security=$MAVEN_SETTINGS_SECURITY verify'
\r
96 stage 'Publish Artifact'
\r
98 withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
\r
100 echo "Artifact: " + DOCKER_REGISTRY
\r
103 docker login $DOCKER_REGISTRY --username $USERNAME --password $PASSWORD
\r
104 docker build -t $IMAGE_NAME -f target/Dockerfile target
\r
105 docker push $IMAGE_NAME
\r
110 if (PHASES.contains("DEPLOY") || PHASES.contains("UNDEPLOY") || PHASES.contains("UNDEPLOYFORCE")) {
\r
114 //check if helm exists if not install
\r
115 if (fileExists('linux-amd64/helm')) {
\r
117 echo "helm is already installed"
\r
122 echo "installing helm"
\r
123 wget https://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
\r
124 tar -xf helm-v2.8.2-linux-amd64.tar.gz
\r
125 rm helm-v2.8.2-linux-amd64.tar.gz
\r
129 withCredentials([file(credentialsId: KUBE_CONFIG, variable: 'KUBECONFIG')]) {
\r
132 //check if charts are valid, and then perform dry run, if successful then upgrade/install charts
\r
134 if (PHASES.contains("UNDEPLOY")) {
\r
138 helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID
\r
141 if (PHASES.contains("UNDEPLOYFORCE")) {
\r
142 stage 'Undeploy Force'
\r
146 helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID &
\r
147 chmod 755 forceDelete.sh
\r
148 ./forceDelete.sh $ARTIFACT_ID
\r
153 //NOTE Double quotes are used below to access groovy variables like artifact_id and tiller_namespace
\r
154 if (PHASES.contains("DEPLOY")) {
\r
157 usernamePassword(credentialsId: OTF_MONGO_DB, usernameVariable: 'USERNAME_MONGO', passwordVariable: 'PASSWORD_MONGO'),
\r
158 usernamePassword(credentialsId: OTF_CAMUNDA_DB, usernameVariable: 'USERNAME_CAMUNDA', passwordVariable: 'PASSWORD_CAMUNDA')
\r
163 echo "Validate Yaml"
\r
164 helm lint $ARTIFACT_ID
\r
166 echo "View Helm Templates"
\r
167 helm template $ARTIFACT_ID \
\r
168 --set appName=$ARTIFACT_ID \
\r
169 --set version=$VERSION \
\r
170 --set image=$IMAGE_NAME \
\r
171 --set namespace=$TILLER_NAMESPACE \
\r
173 --set otf.mongo.username=$USERNAME_MONGO \
\r
174 --set otf.mongo.password=$PASSWORD_MONGO \
\r
175 --set otf.camunda.db.username=$USERNAME_CAMUNDA \
\r
176 --set otf.camunda.db.password=$PASSWORD_CAMUNDA \
\r
179 echo "Perform Dry Run Of Install"
\r
180 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install --dry-run $ARTIFACT_ID $ARTIFACT_ID \
\r
181 --set version=$VERSION \
\r
182 --set image=$IMAGE_NAME \
\r
183 --set namespace=$TILLER_NAMESPACE \
\r
185 --set otf.mongo.username=$USERNAME_MONGO \
\r
186 --set otf.mongo.password=$PASSWORD_MONGO \
\r
187 --set otf.camunda.db.username=$USERNAME_CAMUNDA \
\r
188 --set otf.camunda.db.password=$PASSWORD_CAMUNDA \
\r
191 echo "Helm Install/Upgrade"
\r
192 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install $ARTIFACT_ID $ARTIFACT_ID \
\r
193 --set version=$VERSION \
\r
194 --set image=$IMAGE_NAME \
\r
195 --set namespace=$TILLER_NAMESPACE \
\r
197 --set otf.mongo.username=$USERNAME_MONGO \
\r
198 --set otf.mongo.password=$PASSWORD_MONGO \
\r
199 --set otf.camunda.db.username=$USERNAME_CAMUNDA \
\r
200 --set otf.camunda.db.password=$PASSWORD_CAMUNDA \
\r