-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsfile
68 lines (58 loc) · 2.36 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
64
65
66
67
68
pipeline
{
agent
{
docker
{
image 'anandhi23/ubuntu-docker-agent:v1'
args '--user root -v /var/run/docker.sock:/var/run/docker.sock'
}
}
stages
{
stage('Checkout')
{
steps
{
echo "Cloning App repository started"
git branch: 'master', url: 'https://github.com/Anandhi-23/Python_CICD.git'
echo "Cloning App repository ended"
}
}//checkout stage closure
stage('Build and Push Docker Image')
{
steps
{
script
{
echo "Building and pushing the image to DockerHub started"
sh 'docker build -t ${DOCKER_IMAGE} .'
def dockerImage = docker.image("${DOCKER_IMAGE}")
docker.withRegistry('https://index.docker.io/v1/', "docker_creds") {
dockerImage.push()
}
echo "Building and pushing the image to DockerHub ended"
}
}
}//build and push docker image stage closure
stage('Update Deployment File')
{
steps
{
withCredentials([string(credentialsId: 'github_creds', variable: 'GITHUB_TOKEN')])
{
sh '''
git config --global --add safe.directory /var/lib/jenkins/workspace/<"ENTER YOUR JENKINS PIPELINE NAME">
git config --global user.email <"ENTER YOUR MAIL ID CONFIGURED WITH VERSION CONTROL SYSTEM">
git config --global user.name <"ENTER YOUR VERSION CONTROL SYSTEM USER NAME">
BUILD_NUMBER=${BUILD_NUMBER}
sed -i "s/python-cicd:.*/python-cicd:${BUILD_NUMBER}/g" python-app-manifests/deployment.yml
git add python-app-manifests/deployment.yml
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
'''
}
}
}//update deployment file stage closure
}//stages closure
}//pipeline closure