Merge "fixing bug in protoc installation in basebuild"
diff --git a/jjb/api-test.yaml b/jjb/api-test.yaml
index 461c039..be15dad 100644
--- a/jjb/api-test.yaml
+++ b/jjb/api-test.yaml
@@ -5,8 +5,8 @@
     id: api-test
     name: 'verify_{project}_api-test'
     description: |
-      <!-- Managed by Jenkins Job Builder -->
-      Created by api-test job-template from ci-management/jjb/api-test.yaml
+      Created by {id} job-template from ci-management/jjb/api-test.yaml, using pipeline: {pipeline_script}
+
 
     triggers:
       - cord-infra-gerrit-trigger-patchset:
diff --git a/jjb/k8install.yaml b/jjb/k8install.yaml
new file mode 100644
index 0000000..b35b41d
--- /dev/null
+++ b/jjb/k8install.yaml
@@ -0,0 +1,60 @@
+---
+# kubespray installation validation job
+
+- project:
+    name: kubespray-install-test
+
+    project-name: '{name}'
+
+    jobs:
+      - 'k8-install'
+
+- job-template:
+    id: 'k8-install'
+    name: 'k8-install'
+
+    description: |
+      <!-- Managed by Jenkins Job Builder -->
+      Created by {id} job-template from ci-management/jjb/k8install.yaml  <br /><br />
+      Validation job for kubespray installation script provided to users/operators
+
+    properties:
+      - cord-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+          artifact-num-to-keep: '{artifact-num-to-keep}'
+
+    wrappers:
+      - lf-infra-wrappers:
+          build-timeout: '{build-timeout}'
+          jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+    parameters:
+      - string:
+          name: executorNode
+          default: 'qa-testvm-pod'
+          description: 'Name of the Jenkins node to run the job on'
+
+      - string:
+          name: branch
+          default: 'master'
+          description: 'Name of the repo branch to use'
+
+      - string:
+         name: configRepoUrl
+         default: 'https://gerrit.opencord.org/pod-configs'
+         description: 'The URL of the POD configs repository'
+
+      - string:
+         name: configRepoBaseDir
+         default: 'pod-configs/'
+         description: 'The directory inside the POD configs repository'
+
+      - string:
+         name: configRepoFile
+         default: 'kubernetes-configs/flex-onf-pod1.yml'
+         description: 'The deployment config file'
+
+    project-type: pipeline
+    concurrent: false
+
+    dsl: !include-raw-escape: pipeline/kubespray-install.groovy
diff --git a/jjb/pipeline/all-xos-api-test-helm.groovy b/jjb/pipeline/all-xos-api-test-helm.groovy
index 3c4957f..c779be3 100644
--- a/jjb/pipeline/all-xos-api-test-helm.groovy
+++ b/jjb/pipeline/all-xos-api-test-helm.groovy
@@ -45,14 +45,69 @@
     stage('patch') {
       steps {
         sh """
+           #!/usr/bin/env bash
+           set -eu -o pipefail
+
+           VERSIONFILE="" # file path to file containing version number
+           NEW_VERSION="" # version number found in VERSIONFILE
+           release_version=0
+
+           function read_version {
+             if [ -f "VERSION" ]
+             then
+               NEW_VERSION=\$(head -n1 "VERSION")
+               VERSIONFILE="VERSION"
+             elif [ -f "package.json" ]
+             then
+               NEW_VERSION=\$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json)
+               VERSIONFILE="package.json"
+             else
+               echo "ERROR: No versioning file found!"
+               exit 1
+             fi
+           }
+
+           # check if the version is a released version
+           function check_if_releaseversion {
+             if [[ "\$NEW_VERSION" =~ ^([0-9]+)\\.([0-9]+)\\.([0-9]+)\$ ]]
+             then
+               echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is a SemVer released version!"
+               releaseversion=1
+             else
+               echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is not a SemVer released version, skipping."
+             fi
+           }
+
            pushd cord
            PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
            repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
+
+           pushd \$PROJECT_PATH
+           echo "Existing git tags:"
+           git tag -n
+
+           read_version
+           check_if_releaseversion
+
+           # perform checks if a released version
+           if [ "\$releaseversion" -eq "1" ]
+           then
+             git config --global user.email "apitest@opencord.org"
+             git config --global user.name "API Test"
+
+             git tag -a "\$NEW_VERSION" -m "Tagged for api test on Gerrit patchset: ${gerritChangeNumber}"
+
+             echo "Tags including new tag:"
+             git tag -n
+
+           fi
            popd
-         """
+           popd
+           """
       }
     }
 
+
     stage('prep') {
       parallel {
 
diff --git a/jjb/pipeline/kubespray-install.groovy b/jjb/pipeline/kubespray-install.groovy
new file mode 100644
index 0000000..676f514
--- /dev/null
+++ b/jjb/pipeline/kubespray-install.groovy
@@ -0,0 +1,52 @@
+/*kubespray installation script test*/
+
+pipeline {
+
+  /* no label, executor is determined by JJB */
+  agent {
+    label "${params.executorNode}"
+  }
+  stages {
+
+    stage ("Parse deployment configuration file") {
+      steps {
+            sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}'
+            sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}'
+            script { deployment_config = readYaml file: "${configRepoBaseDir}${configRepoFile}" }
+          }
+        }
+
+    stage ('Checkout Automation-Tools Repo') {
+      steps {
+        sh '''
+            pushd $WORKSPACE
+            git clone https://gerrit.opencord.org/automation-tools
+            popd
+            '''
+            }
+        }
+
+    stage ('Install Kubespray on Nodes') {
+      steps {
+        sh '''
+            pushd $WORKSPACE/automation-tools/kubespray-installer
+            ./setup.sh -i flex-onf-pod1 ${deployment_config.node1.ip} ${deployment_config.node2.ip} ${deployment_config.node3.ip}
+            popd
+            '''
+            }
+        }
+
+    stage ('Validate Kube Config File') {
+      steps {
+        sh '''
+            pushd $WORKSPACE/automation-tools/kubespray-installer/configs
+            #Validate the conf file
+            export KUBECONFIG=$WORKSPACE/automation-tools/kubespray-installer/configs${deployment_config.pod_config}
+            kubectl get pods
+            popd
+            '''
+            }
+        }
+    }
+
+}