-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathjenkinfilekub
More file actions
51 lines (48 loc) · 1.49 KB
/
jenkinfilekub
File metadata and controls
51 lines (48 loc) · 1.49 KB
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
def dockerfile = 'dockerfile'
def registry = 'localhost:5000'
def imageName = 'myimage'
def imageTag = 'latest'
def manifestFile = 'kubernetes-manifest.yaml'
def namespace = 'default'
def IMAGE_BRANCH_TAG = "${registry}/${imageName}:${imageTag}"
pipeline {
agent any
// Define variables at the top level
// def dockerfile = 'dockerfile'
// def registry = 'localhost:5000'
// def imageName = 'myimage'
// def imageTag = 'latest'
// def manifestFile = 'k8s-deployment.yaml'
// def namespace = 'default'
stages {
stage('Checkout the Git repository') {
steps {
git branch: 'master', url: 'https://github.com/amitopenwriteup/cicd.git'
}
}
stage('Build Docker image') {
steps {
script {
def dockerImage = docker.build("${registry}/${imageName}:${imageTag}", "-f ${dockerfile} .")
dockerImage.push()
}
}
}
stage('Apply Kubernetes manifest') {
steps {
withCredentials([file(credentialsId: '9445dd9b-e604-40cd-a802-79f747011ecb', variable: 'KUBECONFIG')])
{
script {
sh """
sed \
-e "s|{{NAMESPACE}}|${namespace}|g" \
-e "s|{{PULL_IMAGE}}|${IMAGE_BRANCH_TAG}|g" \
${manifestFile} \
| kubectl apply -f -
"""
}
}
}
}
}
}