1pipeline {
2 agent any
3
4 parameters {
5 string(name: 'DEPLOYMENT', defaultValue: 'production')
6 }
7
8 stages {
9 stage('Update Kubeconfig') {
10 steps {
11 withCredentials([[
12 $class: 'AmazonWebServicesCredentialsBinding',
13 credentialsId: "aws-credentials",
14 accessKeyVariable: 'AWS_ACCESS_KEY_ID',
15 secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
16 ]]) {
17 sh """
18 aws eks update-kubeconfig --name python-cluster --region us-east-1
19 kubectl get nodes
20 """
21 }
22 }
23 }
24
25 stage('Deploy App') {
26 steps {
27 withCredentials([[
28 $class: 'AmazonWebServicesCredentialsBinding',
29 credentialsId: "aws-credentials",
30 accessKeyVariable: 'AWS_ACCESS_KEY_ID',
31 secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
32 ]]) {
33 sh """
34 kubectl create namespace python-app --dry-run=client -o yaml | kubectl apply -f -
35 kubectl -n python-app apply -f k8s/deployment.yaml
36 kubectl -n python-app apply -f k8s/services.yaml
37 kubectl -n python-app rollout status deployment/survey-app-deploy
38 """
39 }
40 }
41 }
42
43 stage('Reveal APP URL') {
44 steps {
45 withCredentials([[
46 $class: 'AmazonWebServicesCredentialsBinding',
47 credentialsId: "aws-credentials",
48 accessKeyVariable: 'AWS_ACCESS_KEY_ID',
49 secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
50 ]]) {
51 sh "kubectl -n python-app get svc"
52 }
53 }
54 }
55 }
56}