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: "id_otf_dev"],
\r
22 [$class: 'hudson.model.StringParameterDefinition', name: 'KUBE_CONFIG', defaultValue: "kubeConfig-dev"],
\r
23 [$class: 'hudson.model.StringParameterDefinition', name: 'TILLER_NAMESPACE', defaultValue: "org-oran-otf"]
\r
27 echo "Build branch: ${env.BRANCH_NAME}"
\r
32 PHASES=PHASE.tokenize( '_' );
\r
33 echo "PHASES : " + PHASES
\r
36 ARTIFACT_ID="dmaap-vth";
\r
37 VERSION="0.0.1-SNAPSHOT";
\r
38 NAMESPACE="org-oran-otf"
\r
39 DOCKER_REGISTRY="registry.hub.docker.io"
\r
41 if( ENV.equalsIgnoreCase("dev") ){
\r
42 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + ".dev" + "/" + ARTIFACT_ID + ":" + VERSION
\r
45 if( ENV.equalsIgnoreCase("prod") || ENV.equalsIgnoreCase("prod-dr")){
\r
46 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + ".prod" + "/" + ARTIFACT_ID + ":" + VERSION
\r
50 if( ENV.equalsIgnoreCase("st") ){
\r
51 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + ".st" + "/" + ARTIFACT_ID + ":" + VERSION
\r
55 echo "Artifact: " + IMAGE_NAME
\r
57 withEnv(["PATH=${env.PATH}:${env.WORKSPACE}/linux-amd64", "HELM_HOME=${env.WORKSPACE}"]) {
\r
59 echo "PATH=${env.PATH}"
\r
60 echo "HELM_HOME=${env.HELM_HOME}"
\r
62 if (PHASES.contains("BUILD")){
\r
64 stage 'Publish Artifact'
\r
66 withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
\r
68 echo "Artifact: " + IMAGE_NAME
\r
71 docker login $DOCKER_REGISTRY --username $USERNAME --password $PASSWORD
\r
72 docker build -t $IMAGE_NAME .
\r
73 docker push $IMAGE_NAME
\r
79 if (PHASES.contains("DEPLOY") || PHASES.contains("UNDEPLOY")) {
\r
83 //check if helm exists if not install
\r
84 if(fileExists('linux-amd64/helm')){
\r
86 echo "helm is already installed"
\r
92 echo "installing helm"
\r
93 wget https://storage.googleapis.com/kubernetes-helm/helm-v2.14.3-linux-amd64.tar.gz
\r
94 tar -xf helm-v2.14.3-linux-amd64.tar.gz
\r
95 rm helm-v2.14.3-linux-amd64.tar.gz
\r
99 withCredentials([file(credentialsId: KUBE_CONFIG, variable: 'KUBECONFIG')]) {
\r
102 //check if charts are valid, and then perform dry run, if successful then upgrade/install charts
\r
104 if (PHASES.contains("UNDEPLOY") ) {
\r
108 helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID
\r
112 //NOTE Double quotes are used below to access groovy variables like artifact_id and tiller_namespace
\r
113 if (PHASES.contains("DEPLOY") ){
\r
115 withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
\r
119 echo "Validate Yaml"
\r
120 helm lint $ARTIFACT_ID
\r
122 echo "View Helm Templates"
\r
123 helm template $ARTIFACT_ID --set appName=$ARTIFACT_ID \
\r
124 --set appName=$ARTIFACT_ID \
\r
125 --set version=$VERSION \
\r
127 --set image=$IMAGE_NAME \
\r
128 --set namespace=$TILLER_NAMESPACE \
\r
129 --set credentials.username= $USERNAME \
\r
130 --set credentials.password= $PASSWORD
\r
132 echo "Perform Dry Run Of Install"
\r
133 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install --dry-run $ARTIFACT_ID $ARTIFACT_ID \
\r
134 --set appName=$ARTIFACT_ID \
\r
135 --set version=$VERSION \
\r
137 --set image=$IMAGE_NAME \
\r
138 --set namespace=$TILLER_NAMESPACE \
\r
139 --set credentials.username=$USERNAME \
\r
140 --set credentials.password=$PASSWORD
\r
143 echo "Helm Install/Upgrade"
\r
144 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install $ARTIFACT_ID $ARTIFACT_ID \
\r
145 --set appName=$ARTIFACT_ID \
\r
146 --set version=$VERSION \
\r
148 --set image=$IMAGE_NAME \
\r
149 --set namespace=$TILLER_NAMESPACE \
\r
150 --set credentials.username=$USERNAME \
\r
151 --set credentials.password=$PASSWORD
\r