blob: c2d0b5c75486c3917e03a4665611f090ad907cf0 [file] [log] [blame]
Rohan Patelf49bd1e2019-09-23 15:04:19 -04001#!/usr/bin/env groovy
2
3
4properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
5 [$class: 'hudson.model.StringParameterDefinition', name: 'PHASE', defaultValue: "BUILD"],
6 [$class: 'hudson.model.StringParameterDefinition', name: 'ENV', defaultValue: "dev"],
7 [$class: 'hudson.model.StringParameterDefinition', name: 'MECHID', defaultValue: "id"],
8 [$class: 'hudson.model.StringParameterDefinition', name: 'KUBE_CONFIG', defaultValue: "kubeConfig-dev"],
9 [$class: 'hudson.model.StringParameterDefinition', name: 'TILLER_NAMESPACE', defaultValue: "org-onap-otf"]
10]]])
11
12
13echo "Build branch: ${env.BRANCH_NAME}"
14
15node("docker"){
16 stage 'Checkout'
17 checkout scm
18 PHASES=PHASE.tokenize( '_' );
19 echo "PHASES : " + PHASES
20 ARTIFACT_ID="otf-aaf-credential-generator"
21 echo "Tiller Namespace: " + TILLER_NAMESPACE
22
23 withEnv(["PATH=${env.PATH}:${tool 'jdk180'}:${env.WORKSPACE}/linux-amd64", "JAVA_HOME=${tool 'jdk180'}","HELM_HOME=${env.WORKSPACE}"]) {
24
25 echo "PATH=${env.PATH}"
26 echo "JAVA_HOME=${env.JAVA_HOME}"
27 echo "HELM_HOME=${env.HELM_HOME}"
28
29 wrap([$class: 'ConfigFileBuildWrapper', managedFiles: [
30 [fileId: 'maven-settings.xml', variable: 'MAVEN_SETTINGS']
31 ]]) {
32
33 if (PHASES.contains("DEPLOY") || PHASES.contains("UNDEPLOY")) {
34 stage 'Init Helm'
35
36 //check if helm exists if not install
37 if(fileExists('linux-amd64/helm')){
38 sh """
39 echo "helm is already installed"
40 """
41 }
42 else{
43 //download helm
44 sh """
45 echo "installing helm"
46 wget https://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
47 tar -xf helm-v2.8.2-linux-amd64.tar.gz
48 rm helm-v2.8.2-linux-amd64.tar.gz
49 """
50 }
51
52 withCredentials([file(credentialsId: KUBE_CONFIG, variable: 'KUBECONFIG')]) {
53
54 dir('helm'){
55 //check if charts are valid, and then perform dry run, if successful then upgrade/install charts
56
57 if (PHASES.contains("UNDEPLOY") ) {
58 stage 'Undeploy'
59
60 sh """
61 helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID
62 """
63 }
64
65 //NOTE Double quotes are used below to access groovy variables like artifact_id and tiller_namespace
66 if (PHASES.contains("DEPLOY") ){
67 stage 'Deploy'
68 withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
69
70 //Note: KEYFILE_PATH must be within helm/$ARTIFACT_ID and must be relative path starting from that directory
71 sh """
72
73 echo "Remove old key info"
74 rm -rf keyfile;
75 rm -rf digest.txt
76 rm -rf $ARTIFACT_ID/keyfile
77
78 ls
79 echo "Create keyfile and digest"
80 java -jar ../aaf_cadi_core_2.1.10_SNAPSHOT.jar keygen keyfile
81 java -jar ../aaf_cadi_core_2.1.10_SNAPSHOT.jar digest $PASSWORD keyfile > digest.txt 2>&1
82
83 cp keyfile $ARTIFACT_ID
84 KEYFILE_PATH=keyfile
85 DIGEST="enc:"
86 DIGEST+=\$(cat digest.txt)
87 echo \$DIGEST
88 echo "Validate Yaml"
89 helm lint $ARTIFACT_ID
90
91 echo "View Helm Templates"
92 helm template $ARTIFACT_ID --set Secret.aafId=$USERNAME --set Secret.aafPassword=\$DIGEST --set Secret.aafMechPassword=$PASSWORD --set keyfilePath=\$KEYFILE_PATH
93
94 echo "Perform Dry Run Of Install"
95 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install --dry-run $ARTIFACT_ID $ARTIFACT_ID --set Secret.aafId=$USERNAME --set Secret.aafPassword=\$DIGEST --set Secret.aafMechPassword=$PASSWORD --set keyfilePath=\$KEYFILE_PATH
96
97 echo "Helm Install/Upgrade"
98 helm upgrade --tiller-namespace=$TILLER_NAMESPACE --install $ARTIFACT_ID $ARTIFACT_ID --set Secret.aafId=$USERNAME --set Secret.aafPassword=\$DIGEST --set Secret.aafMechPassword=$PASSWORD --set keyfilePath=\$KEYFILE_PATH
99
100 rm -rf $ARTIFACT_ID/keyfile
101 rm -rf keyfile
102 rm -rf digest.txt
103 """
104 }
105 }
106
107 }
108 }
109 }
110 }
111 }
112}