Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 1 | /* helm-api-test pipeline */ |
| 2 | |
| 3 | pipeline { |
| 4 | |
| 5 | /* no label, executor is determined by JJB */ |
| 6 | agent { |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 7 | label "${params.executorNode}" |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 8 | } |
| 9 | |
| 10 | stages { |
| 11 | |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 12 | stage('repo') { |
Zack Williams | 90cf9fd | 2018-05-11 10:26:21 -0700 | [diff] [blame] | 13 | steps { |
| 14 | checkout(changelog: false, \ |
| 15 | poll: false, |
| 16 | scm: [$class: 'RepoScm', \ |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 17 | manifestRepositoryUrl: "${params.manifestUrl}", \ |
| 18 | manifestBranch: "${params.manifestBranch}", \ |
Zack Williams | 90cf9fd | 2018-05-11 10:26:21 -0700 | [diff] [blame] | 19 | currentBranch: true, \ |
| 20 | destinationDir: 'cord', \ |
| 21 | forceSync: true, |
| 22 | resetFirst: true, \ |
| 23 | quiet: true, \ |
| 24 | jobs: 4, \ |
| 25 | showAllChanges: true] \ |
| 26 | ) |
| 27 | } |
| 28 | } |
| 29 | |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 30 | stage('patch') { |
| 31 | steps { |
| 32 | sh """ |
Zack Williams | c61b93a | 2018-06-28 11:59:47 -0700 | [diff] [blame] | 33 | #!/usr/bin/env bash |
| 34 | set -eu -o pipefail |
| 35 | |
| 36 | VERSIONFILE="" # file path to file containing version number |
| 37 | NEW_VERSION="" # version number found in VERSIONFILE |
| 38 | release_version=0 |
| 39 | |
| 40 | function read_version { |
| 41 | if [ -f "VERSION" ] |
| 42 | then |
| 43 | NEW_VERSION=\$(head -n1 "VERSION") |
| 44 | VERSIONFILE="VERSION" |
| 45 | elif [ -f "package.json" ] |
| 46 | then |
| 47 | NEW_VERSION=\$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json) |
| 48 | VERSIONFILE="package.json" |
| 49 | else |
| 50 | echo "ERROR: No versioning file found!" |
| 51 | exit 1 |
| 52 | fi |
| 53 | } |
| 54 | |
| 55 | # check if the version is a released version |
| 56 | function check_if_releaseversion { |
| 57 | if [[ "\$NEW_VERSION" =~ ^([0-9]+)\\.([0-9]+)\\.([0-9]+)\$ ]] |
| 58 | then |
| 59 | echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is a SemVer released version!" |
| 60 | releaseversion=1 |
| 61 | else |
| 62 | echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is not a SemVer released version, skipping." |
| 63 | fi |
| 64 | } |
| 65 | |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 66 | pushd cord |
Zack Williams | 9815fd5 | 2018-05-15 16:42:00 -0700 | [diff] [blame] | 67 | PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml) |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 68 | repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}" |
Zack Williams | c61b93a | 2018-06-28 11:59:47 -0700 | [diff] [blame] | 69 | |
| 70 | pushd \$PROJECT_PATH |
| 71 | echo "Existing git tags:" |
| 72 | git tag -n |
| 73 | |
| 74 | read_version |
| 75 | check_if_releaseversion |
| 76 | |
| 77 | # perform checks if a released version |
| 78 | if [ "\$releaseversion" -eq "1" ] |
| 79 | then |
| 80 | git config --global user.email "apitest@opencord.org" |
| 81 | git config --global user.name "API Test" |
| 82 | |
| 83 | git tag -a "\$NEW_VERSION" -m "Tagged for api test on Gerrit patchset: ${gerritChangeNumber}" |
| 84 | |
| 85 | echo "Tags including new tag:" |
| 86 | git tag -n |
| 87 | |
| 88 | fi |
| 89 | popd |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 90 | popd |
| 91 | """ |
| 92 | } |
| 93 | } |
| 94 | |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 95 | stage('prep') { |
| 96 | parallel { |
| 97 | |
| 98 | stage('images') { |
| 99 | steps { |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 100 | sh ''' |
Zack Williams | edb3b80 | 2018-05-25 17:39:03 -0700 | [diff] [blame] | 101 | pushd cord/automation-tools/developer |
| 102 | ./imagebuilder.py -f ../../helm-charts/examples/api-test-images.yaml |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 103 | popd |
| 104 | ''' |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | stage('minikube') { |
| 109 | steps { |
| 110 | /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */ |
| 111 | sh ''' |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 112 | export MINIKUBE_WANTUPDATENOTIFICATION=false |
| 113 | export MINIKUBE_WANTREPORTERRORPROMPT=false |
| 114 | export CHANGE_MINIKUBE_NONE_USER=true |
| 115 | export MINIKUBE_HOME=$HOME |
| 116 | mkdir -p $HOME/.kube || true |
| 117 | touch $HOME/.kube/config |
| 118 | export KUBECONFIG=$HOME/.kube/config |
| 119 | sudo -E /usr/bin/minikube start --vm-driver=none |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 120 | ''' |
Zack Williams | 9815fd5 | 2018-05-15 16:42:00 -0700 | [diff] [blame] | 121 | script { |
| 122 | timeout(3) { |
| 123 | waitUntil { |
| 124 | sleep 5 |
| 125 | def kc_ret = sh script: "kubectl get po", returnStatus: true |
| 126 | return (kc_ret == 0); |
| 127 | } |
| 128 | } |
| 129 | } |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | stage('helm') { |
| 136 | steps { |
Zack Williams | 9815fd5 | 2018-05-15 16:42:00 -0700 | [diff] [blame] | 137 | sh ''' |
| 138 | helm init |
| 139 | sleep 60 |
| 140 | helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/ |
| 141 | ''' |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | stage('xos') { |
| 146 | steps { |
| 147 | sh ''' |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 148 | pushd cord/helm-charts |
| 149 | helm dep up xos-core |
Zack Williams | 4c14383 | 2018-05-16 14:19:29 -0700 | [diff] [blame] | 150 | helm install -f examples/api-test-values.yaml xos-core -n xos-core |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 151 | sleep 60 |
Zack Williams | 9815fd5 | 2018-05-15 16:42:00 -0700 | [diff] [blame] | 152 | helm status xos-core |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 153 | popd |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 154 | ''' |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | stage('test'){ |
| 159 | steps { |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 160 | sh ''' |
| 161 | helm test xos-core |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 162 | mkdir -p ./RobotLogs; |
| 163 | cp /tmp/helm_test_xos_core_logs_*/* ./RobotLogs |
| 164 | ''' |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 165 | |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 166 | step([$class: 'RobotPublisher', |
| 167 | disableArchiveOutput: false, |
| 168 | logFileName: 'RobotLogs/log*.html', |
| 169 | otherFiles: '', |
| 170 | outputFileName: 'RobotLogs/output*.xml', |
| 171 | outputPath: '.', |
| 172 | passThreshold: 100, |
| 173 | reportFileName: 'RobotLogs/report*.html', |
| 174 | unstableThreshold: 0]); |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | post { |
| 180 | always { |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 181 | sh ''' |
Zack Williams | 9815fd5 | 2018-05-15 16:42:00 -0700 | [diff] [blame] | 182 | kubectl get pods --all-namespaces |
| 183 | helm list |
| 184 | kubectl logs xos-core-api-test |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 185 | kubectl delete pod xos-core-api-test |
| 186 | helm delete --purge xos-core |
Zack Williams | a834c34 | 2018-05-31 11:30:15 -0700 | [diff] [blame] | 187 | minikube delete |
Zack Williams | dc6cf04 | 2018-05-14 13:00:57 -0700 | [diff] [blame] | 188 | ''' |
Zack Williams | 84a193e | 2018-05-08 15:57:45 -0700 | [diff] [blame] | 189 | deleteDir() |
| 190 | } |
| 191 | } |
| 192 | } |