-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
55 lines (50 loc) · 2.08 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
pipeline {
agent any
environment {
DOCKERHUB_CREDENTIALS = credentials('dockerhub')
GIT_REPO_URL = 'https://github.com/shnartho/go-jenkins-argocd-deployment.git'
GIT_REPO_CREDENTIALS = credentials('git_credentials')
}
stages {
stage('Build image') {
steps {
sh 'docker build -t shnartho/go-jenkins-argocd:$BUILD_NUMBER .'
}
}
stage('Login to dockerhub') {
steps {
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
stage('Push image') {
steps {
sh 'docker push shnartho/go-jenkins-argocd:$BUILD_NUMBER'
}
}
stage('Update Deployment File') {
steps {
sh 'rm -rf repository'
withCredentials([usernamePassword(credentialsId: 'git_credentials', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh "git clone $GIT_REPO_URL repository"
}
dir('repository') {
// Update your deployment file with the new image tag
sh "sed -i 's|image: shnartho/go-jenkins-argocd:[0-9]*|image: shnartho/go-jenkins-argocd:$BUILD_NUMBER|' deployment.yaml"
// Commit and push the changes
sh 'git config user.email "shnartho@gmail.com"'
sh 'git config user.name "shnartho"'
sh 'git add deployment.yaml'
sh 'git commit -m "Update deployment.yaml"'
withCredentials([usernamePassword(credentialsId: 'git_credentials', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh 'git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/shnartho/go-jenkins-argocd-deployment.git'
}
}
}
}
}
post {
always {
sh 'docker logout'
}
}
}