blob: 2925236b1e76fc2407d44603643e9ae3799c30b2 [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}")
Hung-Wei Chiu99bff2f2020-09-17 13:05:31 -070010 rancher_token = credentials("${params.rancher_cli_env}")
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -070011 }
12 stages {
13 stage('Install tools') {
14 steps {
15 sh '''
16 set -x
17 apt-get update -y
18 apt-get install -y curl wget jq git
19
20 # Install kubectl
21 curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
22 chmod +x ./kubectl
23 mv ./kubectl /usr/local/bin/kubectl
24
25 # Install rancher
26 wget https://github.com/rancher/cli/releases/download/v2.4.5/rancher-linux-amd64-v2.4.5.tar.gz
27 tar -xvf rancher-linux-amd64-v2.4.5.tar.gz
28 mv rancher-v2.4.5/rancher /usr/local/bin
29
30 rm rancher-linux-amd64-v2.4.5.tar.gz
31 rm -rf rancher-v2.4.5
32 # Test Kubectl & Rancher
33 KUBE_CONFIG=$KUBECONFIG kubectl get nodes
34 rancher --version
35 '''
36 }
37 }
Hung-Wei Chiu99bff2f2020-09-17 13:05:31 -070038 stage('Init git') {
39 steps {
40 withCredentials([sshUserPrivateKey(credentialsId: "aether_jenkins", keyFileVariable: 'keyfile')]) {
41
42 sh """#!/bin/bash
43 set -x
44 mkdir -p ~/.ssh
45 ssh-keyscan -t rsa -p 29418 ${git_server} >> ~/.ssh/known_hosts
46cat <<EOF > ~/.ssh/config
47Host ${git_server}
48 User ${git_user}
49 Hostname ${git_server}
50 Port 29418
51 IdentityFile ${keyfile}
52EOF
53
54 git clone "ssh://${git_server}:29418/${git_repo}"
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -070055 if [ ! -z ${config_review} ] && [ ! -z ${config_patchset} ]; then
Hung-Wei Chiu99bff2f2020-09-17 13:05:31 -070056 CFG_LAST2=\$(echo ${config_review} | tail -c 3)
57 git fetch "ssh://@${git_server}:29418/${git_repo}" refs/changes/\${CFG_LAST2}/${config_review}/${config_patchset} && git checkout FETCH_HEAD
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -070058 fi
Hung-Wei Chiu99bff2f2020-09-17 13:05:31 -070059
60 """
61 }
62 }
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -070063 }
Hung-Wei Chiu99bff2f2020-09-17 13:05:31 -070064
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -070065 stage('Login Rancher') {
66 steps {
67 sh '''
68 rancher login ${rancher_server} --token ${rancher_token} --context ${rancher_context}:${rancher_project}
69 '''
70 }
71 }
72 stage('Uninstall Apps') {
73 options {
74 timeout(time: 90, unit: "SECONDS")
75 }
76 steps {
77 sh '''
78 for app in $(rancher apps ls -q | grep -E '(fluentbit)'); do rancher apps delete $app; done
79
80 until [ "$(rancher apps ls -q | grep -E '(fluentbit)')" = "" ]; do echo "wait deleted apps"; rancher apps ls ; sleep 1; done
81 '''
82 }
83 }
84 stage('Install apps') {
85 options {
86 timeout(time: 600, unit: "SECONDS")
87 }
88 steps {
89 sh '''
Hung-Wei Chiu99bff2f2020-09-17 13:05:31 -070090 cd ${workspace}/${git_repo}/deployment-configs/aether/apps/${config_env}/
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -070091 until rancher apps install --answers fluentbit-ans.yml --namespace ${fluentbit_ns} cattle-global-data:fluent-fluent-bit fluentbit; do :; done
92 apps=$(rancher apps -q | grep fluentbit)
93 for app in $apps; do until rancher wait $app --timeout 20; do :; done; rancher apps ls; done
94 '''
95 }
96 }
97
98 }
99 post {
100 always {
Hung-Wei Chiu99bff2f2020-09-17 13:05:31 -0700101 sh """
102 rm -rf ${workspace}/${git_repo}
103 """
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -0700104 cleanWs()
105 }
106 }
107}