-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
63 lines (57 loc) · 2.05 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
61
62
63
pipeline {
agent any
environment {
DOCKER_IMAGE_NAME = 'prady0t/pipeline'
}
stages {
stage("echo") {
steps {
echo "Hello"
}
}
stage("Checkout") {
steps {
script {
checkout([$class: 'GitSCM', branches: [[name: 'main']], userRemoteConfigs: [[url: 'https://github.com/prady0t/CI-CD-pipeline-app']]])
}
}
}
stage("Build Image") {
steps {
script {
def dockerImage = docker.build("${DOCKER_IMAGE_NAME}:${BUILD_NUMBER}", " . ")
}
}
}
stage("Push Image") {
steps {
// Authenticate with Docker Hub
withCredentials([usernamePassword(credentialsId: 'dockerhub_cred', passwordVariable: 'DOCKERHUB_PASSWORD', usernameVariable: 'DOCKERHUB_USERNAME')]) {
// Log in to Docker Hub
sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_PASSWORD}"
// Push the Docker image to Docker Hub
sh "docker push ${DOCKER_IMAGE_NAME}:${BUILD_NUMBER}"
}
}
}
stage('Update Deployment File') {
environment {
GIT_REPO_NAME = "CI-CD-pipeline-manifests"
GIT_USER_NAME = "prady0t"
}
steps {
withCredentials([string(credentialsId: 'Github', variable: 'GITHUB_TOKEN')]) {
sh '''
git config user.email "[email protected]"
git config user.name "prady0t"
BUILD_NUMBER=${BUILD_NUMBER}
sed -i "s/toBeReplaced/${BUILD_NUMBER}/g" mainfest/deployment.yaml
git add .
git commit -m "Update deployment image to version ${BUILD_NUMBER}"
git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:master
'''
}
}
}
}
}