blob: aa5daa129dda947733d90f62d4b11a95e41efcc9 [file] [log] [blame]
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -07001pipeline {
2 agent {
3 docker {
4 image 'ubuntu:18.04'
5 args '-u root:sudo'
6 }
7 }
8 environment {
9 KUBECONFIG = credentials("${params.k8s_config}")
10 git_password = credentials("${params.git_password_env}")
11 rancher_token = credentials("${params.rancher_api_env}")
12 }
13 stages {
14 stage('Install tools') {
15 steps {
16 sh '''
17 set -x
18 apt-get update -y
19 apt-get install -y curl wget jq git
20
21 # Install kubectl
22 curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
23 chmod +x ./kubectl
24 mv ./kubectl /usr/local/bin/kubectl
25
26 # Install rancher
27 wget https://github.com/rancher/cli/releases/download/v2.4.5/rancher-linux-amd64-v2.4.5.tar.gz
28 tar -xvf rancher-linux-amd64-v2.4.5.tar.gz
29 mv rancher-v2.4.5/rancher /usr/local/bin
30
31 rm rancher-linux-amd64-v2.4.5.tar.gz
32 rm -rf rancher-v2.4.5
33 # Test Kubectl & Rancher
34 KUBE_CONFIG=$KUBECONFIG kubectl get nodes
35 rancher --version
36 '''
37 }
38 }
39 stage('Clone Config Repo') {
40 options {
41 timeout(time: 10, unit: "SECONDS")
42 }
43 steps {
44 sh '''
45 git clone https://${git_user}:${git_password}@${git_server}/${git_repo}
46 if [ ! -z ${config_review} ] && [ ! -z ${config_patchset} ]; then
47 cd ${git_repo}
48 CFG_LAST2=$(echo ${config_review} | tail -c 3)
49 git fetch "https://${git_user}:${git_password}@${git_server}/a/${git_repo}" refs/changes/${CFG_LAST2}/${config_review}/${config_patchset} && git checkout FETCH_HEAD
50 git checkout FETCH_HEAD
51 cd ..
52 fi
53 '''
54 }
55 }
56 stage('Login Rancher') {
57 steps {
58 sh '''
59 rancher login ${rancher_server} --token ${rancher_token} --context ${rancher_context}:${rancher_project}
60 '''
61 }
62 }
63 stage('Uninstall Apps') {
64 options {
65 timeout(time: 90, unit: "SECONDS")
66 }
67 steps {
68 sh '''
69 for app in $(rancher apps ls -q | grep -E '(telegraf)'); do rancher apps delete $app; done
70
71 until [ "$(rancher apps ls -q | grep -E '(telegraf)')" = "" ]; do echo "wait deleted apps"; rancher apps ls ; sleep 1; done
72 '''
73 }
74 }
75 stage('Install apps') {
76 options {
77 timeout(time: 600, unit: "SECONDS")
78 }
79 steps {
80 sh '''
81 cd ${git_repo}/deployment-configs/aether/apps/${config_env}/
82 until rancher apps install --answers telegraf-ans.yml --namespace ${telegraf_ns} cattle-global-data:influxdata-telegraf telegraf; do :; done
83 apps=$(rancher apps -q | grep telegraf)
84 for app in $apps; do until rancher wait $app --timeout 20; do :; done; rancher apps ls; done
85 '''
86 }
87 }
88
89 }
90 post {
91 always {
92 cleanWs()
93 }
94 }
95}