1 #!/usr/bin/env groovy
\r
4 properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
\r
5 [$class: 'hudson.model.StringParameterDefinition', name: 'PHASE', defaultValue: "BUILD"],
\r
6 [$class: 'hudson.model.StringParameterDefinition', name: 'ENV', defaultValue: "dev"],
\r
7 [$class: 'hudson.model.StringParameterDefinition', name: 'MECHID', defaultValue: "username"],
\r
8 [$class: 'hudson.model.StringParameterDefinition', name: 'KUBE_CONFIG', defaultValue: "kubeConfig-dev"],
\r
9 [$class: 'hudson.model.StringParameterDefinition', name: 'OTF_MONGO_DB', defaultValue: "otf_mongo_dev_db"],
\r
10 [$class: 'hudson.model.StringParameterDefinition', name: 'OTF_CAMUNDA_DB', defaultValue: "otf_camunda_dev_db"],
\r
11 [$class: 'hudson.model.StringParameterDefinition', name: 'TILLER_NAMESPACE', defaultValue: "org.oran.otf"]
\r
16 echo "Build branch: ${env.BRANCH_NAME}"
\r
21 PHASES = PHASE.tokenize('_');
\r
22 echo "PHASES : " + PHASES
\r
23 pom = readMavenPom file: 'pom.xml'
\r
24 ARTIFACT_ID = pom.artifactId;
\r
25 VERSION = pom.version;
\r
26 LABEL_VERSION = pom.version.replaceAll("\\.", "-");
\r
27 echo "LabelVerion: " + LABEL_VERSION
\r
28 NAMESPACE = pom.groupId
\r
29 echo "Tiller Namespace: " + TILLER_NAMESPACE
\r
30 DOCKER_REGISTRY = pom.properties['docker.registry']
\r
32 if( ENV.equalsIgnoreCase("dev") ){
\r
33 IMAGE_NAME = pom.properties['docker.registry'] + "/" + NAMESPACE + "/" + ARTIFACT_ID + ":" + VERSION
\r
35 if( ENV.equalsIgnoreCase("prod") || ENV.equalsIgnoreCase("prod-dr") ){
\r
36 IMAGE_NAME = pom.properties['docker.registry'] + "/" + NAMESPACE + ".prod" + "/" + ARTIFACT_ID + ":" + VERSION
\r
39 if( ENV.equalsIgnoreCase("st") ){
\r
40 IMAGE_NAME = pom.properties['docker.registry'] + "/" + NAMESPACE + ".st" + "/" + ARTIFACT_ID + ":" + VERSION
\r
42 echo "Artifact: " + IMAGE_NAME
\r
45 if( ENV.equalsIgnoreCase("dev") ){
\r
46 ROUTER_CONFIG="mysqlRouterConfig-dev.ini"
\r
48 if( ENV.equalsIgnoreCase("st") ){
\r
49 ROUTER_CONFIG="mysqlRouterConfig-st.ini"
\r
51 if( ENV.equalsIgnoreCase("prod") || ENV.equalsIgnoreCase("prod-dr")){
\r
52 ROUTER_CONFIG="mysqlRouterConfig-prod.ini"
\r
55 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
57 echo "JAVA_HOME=${env.JAVA_HOME}"
\r
58 echo "MAVEN_HOME=${env.MAVEN_HOME}"
\r
59 echo "PATH=${env.PATH}"
\r
60 echo "HELM_HOME=${env.HELM_HOME}"
\r
62 wrap([$class: 'ConfigFileBuildWrapper', managedFiles: [
\r
63 [fileId: 'maven-settings.xml', variable: 'MAVEN_SETTINGS'],
\r
64 [fileId: 'maven-settings-security.xml', variable: 'MAVEN_SETTINGS_SECURITY']
\r
68 if (PHASES.contains("BUILD")) {
\r
70 sh 'mvn -s $MAVEN_SETTINGS -Dsettings.security=$MAVEN_SETTINGS_SECURITY clean compile'
\r
73 sh 'mvn -s $MAVEN_SETTINGS -Dsettings.security=$MAVEN_SETTINGS_SECURITY test'
\r
76 sh 'mvn -s $MAVEN_SETTINGS -Dsettings.security=$MAVEN_SETTINGS_SECURITY package'
\r
77 //sh 'mvn -DskipTests -Dmaven.test.skip=true -s $MAVEN_SETTINGS package'
\r
80 sh 'mvn -s $MAVEN_SETTINGS -Dsettings.security=$MAVEN_SETTINGS_SECURITY verify'
\r
82 stage 'Publish Artifact'
\r
84 withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
\r
86 echo "Artifact: " + DOCKER_REGISTRY
\r
89 docker login $DOCKER_REGISTRY --username $USERNAME --password $PASSWORD
\r
90 docker build -t $IMAGE_NAME -f target/Dockerfile target
\r
91 docker push $IMAGE_NAME
\r
96 if (PHASES.contains("DEPLOY") || PHASES.contains("UNDEPLOY") || PHASES.contains("UNDEPLOYFORCE")) {
\r
100 //check if helm exists if not install
\r
101 if (fileExists('linux-amd64/helm')) {
\r
103 echo "helm is already installed"
\r
108 echo "installing helm"
\r
109 wget https://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
\r
110 tar -xf helm-v2.8.2-linux-amd64.tar.gz
\r
111 rm helm-v2.8.2-linux-amd64.tar.gz
\r
115 withCredentials([file(credentialsId: KUBE_CONFIG, variable: 'KUBECONFIG')]) {
\r
118 //check if charts are valid, and then perform dry run, if successful then upgrade/install charts
\r
120 if (PHASES.contains("UNDEPLOY")) {
\r
124 helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID
\r
127 if (PHASES.contains("UNDEPLOYFORCE")) {
\r
128 stage 'Undeploy Force'
\r
132 helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID &
\r
133 chmod 755 forceDelete.sh
\r
134 ./forceDelete.sh $ARTIFACT_ID
\r
139 //NOTE Double quotes are used below to access groovy variables like artifact_id and tiller_namespace
\r
140 if (PHASES.contains("DEPLOY")) {
\r
143 usernamePassword(credentialsId: OTF_MONGO_DB, usernameVariable: 'USERNAME_MONGO', passwordVariable: 'PASSWORD_MONGO'),
\r
144 usernamePassword(credentialsId: OTF_CAMUNDA_DB, usernameVariable: 'USERNAME_CAMUNDA', passwordVariable: 'PASSWORD_CAMUNDA')
\r
149 echo "Validate Yaml"
\r
150 helm lint $ARTIFACT_ID
\r
152 echo "View Helm Templates"
\r
153 helm template $ARTIFACT_ID \
\r
154 --set appName=$ARTIFACT_ID \
\r
155 --set version=$VERSION \
\r
156 --set image=$IMAGE_NAME \
\r
157 --set namespace=$TILLER_NAMESPACE \
\r
159 --set otf.mongo.username=$USERNAME_MONGO \
\r
160 --set otf.mongo.password=$PASSWORD_MONGO \
\r
161 --set otf.camunda.db.username=$USERNAME_CAMUNDA \
\r
162 --set otf.camunda.db.password=$PASSWORD_CAMUNDA \
\r
165 echo "Perform Dry Run Of Install"
\r
166 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install --dry-run $ARTIFACT_ID $ARTIFACT_ID \
\r
167 --set version=$VERSION \
\r
168 --set image=$IMAGE_NAME \
\r
169 --set namespace=$TILLER_NAMESPACE \
\r
171 --set otf.mongo.username=$USERNAME_MONGO \
\r
172 --set otf.mongo.password=$PASSWORD_MONGO \
\r
173 --set otf.camunda.db.username=$USERNAME_CAMUNDA \
\r
174 --set otf.camunda.db.password=$PASSWORD_CAMUNDA \
\r
177 echo "Helm Install/Upgrade"
\r
178 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install $ARTIFACT_ID $ARTIFACT_ID \
\r
179 --set version=$VERSION \
\r
180 --set image=$IMAGE_NAME \
\r
181 --set namespace=$TILLER_NAMESPACE \
\r
183 --set otf.mongo.username=$USERNAME_MONGO \
\r
184 --set otf.mongo.password=$PASSWORD_MONGO \
\r
185 --set otf.camunda.db.username=$USERNAME_CAMUNDA \
\r
186 --set otf.camunda.db.password=$PASSWORD_CAMUNDA \
\r