Rohan Patel | f49bd1e | 2019-09-23 15:04:19 -0400 | [diff] [blame] | 1 | #!/usr/bin/env groovy
|
| 2 |
|
Rohan Patel | e19624e | 2019-11-11 16:30:46 -0500 | [diff] [blame] | 3 | /* Copyright (c) 2019 AT&T Intellectual Property. #
|
| 4 | # #
|
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); #
|
| 6 | # you may not use this file except in compliance with the License. #
|
| 7 | # You may obtain a copy of the License at #
|
| 8 | # #
|
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 #
|
| 10 | # #
|
| 11 | # Unless required by applicable law or agreed to in writing, software #
|
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, #
|
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
| 14 | # See the License for the specific language governing permissions and #
|
| 15 | # limitations under the License. #
|
| 16 | ##############################################################################*/
|
| 17 |
|
Rohan Patel | f49bd1e | 2019-09-23 15:04:19 -0400 | [diff] [blame] | 18 |
|
| 19 | properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
|
| 20 | [$class: 'hudson.model.StringParameterDefinition', name: 'PHASE', defaultValue: "BUILD"],
|
| 21 | [$class: 'hudson.model.StringParameterDefinition', name: 'ENV', defaultValue: "dev"],
|
| 22 | [$class: 'hudson.model.StringParameterDefinition', name: 'MECHID', defaultValue: "id"],
|
| 23 | [$class: 'hudson.model.StringParameterDefinition', name: 'KUBE_CONFIG', defaultValue: "kubeConfig-dev"],
|
| 24 | [$class: 'hudson.model.StringParameterDefinition', name: 'TILLER_NAMESPACE', defaultValue: "org-onap-otf"]
|
| 25 | ]]])
|
| 26 |
|
| 27 |
|
| 28 | echo "Build branch: ${env.BRANCH_NAME}"
|
| 29 |
|
| 30 | node("docker"){
|
| 31 | stage 'Checkout'
|
| 32 | checkout scm
|
| 33 | PHASES=PHASE.tokenize( '_' );
|
| 34 | echo "PHASES : " + PHASES
|
| 35 | ARTIFACT_ID="otf-aaf-credential-generator"
|
| 36 | echo "Tiller Namespace: " + TILLER_NAMESPACE
|
| 37 |
|
| 38 | withEnv(["PATH=${env.PATH}:${tool 'jdk180'}:${env.WORKSPACE}/linux-amd64", "JAVA_HOME=${tool 'jdk180'}","HELM_HOME=${env.WORKSPACE}"]) {
|
| 39 |
|
| 40 | echo "PATH=${env.PATH}"
|
| 41 | echo "JAVA_HOME=${env.JAVA_HOME}"
|
| 42 | echo "HELM_HOME=${env.HELM_HOME}"
|
| 43 |
|
| 44 | wrap([$class: 'ConfigFileBuildWrapper', managedFiles: [
|
| 45 | [fileId: 'maven-settings.xml', variable: 'MAVEN_SETTINGS']
|
| 46 | ]]) {
|
| 47 |
|
| 48 | if (PHASES.contains("DEPLOY") || PHASES.contains("UNDEPLOY")) {
|
| 49 | stage 'Init Helm'
|
| 50 |
|
| 51 | //check if helm exists if not install
|
| 52 | if(fileExists('linux-amd64/helm')){
|
| 53 | sh """
|
| 54 | echo "helm is already installed"
|
| 55 | """
|
| 56 | }
|
| 57 | else{
|
| 58 | //download helm
|
| 59 | sh """
|
| 60 | echo "installing helm"
|
| 61 | wget https://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
|
| 62 | tar -xf helm-v2.8.2-linux-amd64.tar.gz
|
| 63 | rm helm-v2.8.2-linux-amd64.tar.gz
|
| 64 | """
|
| 65 | }
|
| 66 |
|
| 67 | withCredentials([file(credentialsId: KUBE_CONFIG, variable: 'KUBECONFIG')]) {
|
| 68 |
|
| 69 | dir('helm'){
|
| 70 | //check if charts are valid, and then perform dry run, if successful then upgrade/install charts
|
| 71 |
|
| 72 | if (PHASES.contains("UNDEPLOY") ) {
|
| 73 | stage 'Undeploy'
|
| 74 |
|
| 75 | sh """
|
| 76 | helm delete --tiller-namespace=$TILLER_NAMESPACE --purge $ARTIFACT_ID
|
| 77 | """
|
| 78 | }
|
| 79 |
|
| 80 | //NOTE Double quotes are used below to access groovy variables like artifact_id and tiller_namespace
|
| 81 | if (PHASES.contains("DEPLOY") ){
|
| 82 | stage 'Deploy'
|
| 83 | withCredentials([usernamePassword(credentialsId: MECHID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
| 84 |
|
| 85 | //Note: KEYFILE_PATH must be within helm/$ARTIFACT_ID and must be relative path starting from that directory
|
| 86 | sh """
|
| 87 |
|
| 88 | echo "Remove old key info"
|
| 89 | rm -rf keyfile;
|
| 90 | rm -rf digest.txt
|
| 91 | rm -rf $ARTIFACT_ID/keyfile
|
| 92 |
|
| 93 | ls
|
| 94 | echo "Create keyfile and digest"
|
| 95 | java -jar ../aaf_cadi_core_2.1.10_SNAPSHOT.jar keygen keyfile
|
| 96 | java -jar ../aaf_cadi_core_2.1.10_SNAPSHOT.jar digest $PASSWORD keyfile > digest.txt 2>&1
|
| 97 |
|
| 98 | cp keyfile $ARTIFACT_ID
|
| 99 | KEYFILE_PATH=keyfile
|
| 100 | DIGEST="enc:"
|
| 101 | DIGEST+=\$(cat digest.txt)
|
| 102 | echo \$DIGEST
|
| 103 | echo "Validate Yaml"
|
| 104 | helm lint $ARTIFACT_ID
|
| 105 |
|
| 106 | echo "View Helm Templates"
|
| 107 | helm template $ARTIFACT_ID --set Secret.aafId=$USERNAME --set Secret.aafPassword=\$DIGEST --set Secret.aafMechPassword=$PASSWORD --set keyfilePath=\$KEYFILE_PATH
|
| 108 |
|
| 109 | echo "Perform Dry Run Of Install"
|
| 110 | 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
|
| 111 |
|
| 112 | echo "Helm Install/Upgrade"
|
| 113 | 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
|
| 114 |
|
| 115 | rm -rf $ARTIFACT_ID/keyfile
|
| 116 | rm -rf keyfile
|
| 117 | rm -rf digest.txt
|
| 118 | """
|
| 119 | }
|
| 120 | }
|
| 121 |
|
| 122 | }
|
| 123 | }
|
| 124 | }
|
| 125 | }
|
| 126 | }
|
| 127 | } |