-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
60 lines (53 loc) · 1.93 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git(credentialsId: '',
url: 'https://github.com/grantsunny/JTicket.git',
branch: 'main')
}
}
stage('Build & Push Container Image') {
steps {
script {
docker.withRegistry("", "") {
def dockerImage = docker.build("jticket/ticket-service:latest", ".")
dockerImage.tag("${BUILD_NUMBER}")
dockerImage.push("latest")
dockerImage.push("${BUILD_NUMBER}")
}
}
}
}
stage('Setup Kubectl') {
steps {
script {
// Determine the latest version of kubectl
def kubectlVersion = sh(script: "curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt", returnStdout: true).trim()
def kubectlDownloadUrl = "https://storage.googleapis.com/kubernetes-release/release/${kubectlVersion}/bin/linux/amd64/kubectl"
sh "curl -LO ${kubectlDownloadUrl}"
sh "chmod +x ./kubectl"
}
}
}
stage('Deploy to Kubernetes') {
steps {
script {
withKubeConfig([credentialsId: 'stoneticket-dev-kubeconfig']) {
sh './kubectl config set-context --current --namespace=tontix'
sh './kubectl apply -f ./kubernetes/.'
sh './kubectl rollout restart deployment/JTicket'
}
}
}
}
stage('Cleanup the container context') {
steps {
script {
sh 'docker system prune -a -f'
}
}
}
}
}