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
19 properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
\r
20 [$class: 'hudson.model.StringParameterDefinition', name: 'PHASE', defaultValue: "BUILD"],
\r
21 [$class: 'hudson.model.StringParameterDefinition', name: 'ENV', defaultValue: "dev"],
\r
22 [$class: 'hudson.model.StringParameterDefinition', name: 'MECHID', defaultValue: "m13591_otf_dev"],
\r
23 [$class: 'hudson.model.StringParameterDefinition', name: 'KUBE_CONFIG', defaultValue: "kubeConfig-dev"],
\r
24 [$class: 'hudson.model.StringParameterDefinition', name: 'TILLER_NAMESPACE', defaultValue: "com-att-ecomp-otf-dev"]
\r
28 echo "Build branch: ${env.BRANCH_NAME}"
\r
33 PHASES=PHASE.tokenize( '_' );
\r
34 echo "PHASES : " + PHASES
\r
37 ARTIFACT_ID="a1-sdnc-vth";
\r
38 VERSION="0.0.1-SNAPSHOT";
\r
39 NAMESPACE="com.att.ecomp.otf" //TODO change back to org-otf-oran when done testing
\r
40 DOCKER_REGISTRY="dockercentral.it.att.com:5100"
\r
42 if( ENV.equalsIgnoreCase("dev") ){
\r
43 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + ".dev" + "/" + ARTIFACT_ID + ":" + VERSION
\r
46 if( ENV.equalsIgnoreCase("prod") || ENV.equalsIgnoreCase("prod-dr")){
\r
47 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + ".prod" + "/" + ARTIFACT_ID + ":" + VERSION
\r
51 if( ENV.equalsIgnoreCase("st") ){
\r
52 IMAGE_NAME=DOCKER_REGISTRY + "/" + NAMESPACE + ".st" + "/" + ARTIFACT_ID + ":" + VERSION
\r
56 echo "Artifact: " + IMAGE_NAME
\r
58 withEnv(["PATH=${env.PATH}:${env.WORKSPACE}/linux-amd64", "HELM_HOME=${env.WORKSPACE}"]) {
\r
60 echo "PATH=${env.PATH}"
\r
61 echo "HELM_HOME=${env.HELM_HOME}"
\r
63 if (PHASES.contains("BUILD")){
\r
64 dir("./a1-sdnc-vth"){
\r
65 stage 'Publish Artifact'
\r
67 withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
\r
69 echo "Artifact: " + IMAGE_NAME
\r
72 docker login $DOCKER_REGISTRY --username $USERNAME --password $PASSWORD
\r
73 docker build -t $IMAGE_NAME .
\r
74 docker push $IMAGE_NAME
\r
82 if (PHASES.contains("DEPLOY") || PHASES.contains("UNDEPLOY")) {
\r
86 //check if helm exists if not install
\r
87 if(fileExists('linux-amd64/helm')){
\r
89 echo "helm is already installed"
\r
95 echo "installing helm"
\r
96 wget https://storage.googleapis.com/kubernetes-helm/helm-v2.14.3-linux-amd64.tar.gz
\r
97 tar -xf helm-v2.14.3-linux-amd64.tar.gz
\r
98 rm helm-v2.14.3-linux-amd64.tar.gz
\r
102 withCredentials([file(credentialsId: KUBE_CONFIG, variable: 'KUBECONFIG')]) {
\r
104 dir('a1-sdnc-vth/helm'){
\r
105 //check if charts are valid, and then perform dry run, if successful then upgrade/install charts
\r
107 if (PHASES.contains("UNDEPLOY") ) {
\r
111 helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID
\r
115 //NOTE Double quotes are used below to access groovy variables like artifact_id and tiller_namespace
\r
116 if (PHASES.contains("DEPLOY") ){
\r
118 withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
\r
121 echo "Validate Yaml"
\r
122 helm lint $ARTIFACT_ID
\r
124 echo "View Helm Templates"
\r
125 helm template $ARTIFACT_ID --set appName=$ARTIFACT_ID \
\r
126 --set appName=$ARTIFACT_ID \
\r
127 --set version=$VERSION \
\r
129 --set image=$IMAGE_NAME \
\r
130 --set namespace=$TILLER_NAMESPACE
\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
141 echo "Helm Install/Upgrade"
\r
142 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install $ARTIFACT_ID $ARTIFACT_ID \
\r
143 --set appName=$ARTIFACT_ID \
\r
144 --set version=$VERSION \
\r
146 --set image=$IMAGE_NAME \
\r
147 --set namespace=$TILLER_NAMESPACE
\r