-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
73 lines (73 loc) · 2.56 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
69
70
71
72
73
def COMMIT_ID = ''
node('k8sagent') {
properties([
buildDiscarder(logRotator(numToKeepStr: '3', daysToKeepStr: '3')),
pipelineTriggers([
pollSCM('* * * * *')
])
])
stage('Get The Golang project') {
git 'https://github.com/ngostal2019/simpleGoApp.git'
container('jnlp') {
stage('List content of Go project') {
COMMIT_ID = sh returnStdout: true, script: 'git log -n 1 --pretty=format:%H | cut -c1-5'
sh """
ls -ltha
pwd
echo $COMMIT_ID
"""
}
}
}
stage('Kaniko builds & Pushes To Docker') {
container('kaniko'){
sh '''
ls -ltah /kaniko/.docker
echo $DOCKER_CRED > /kaniko/.docker/config.json
cat /kaniko/.docker/config.json
'''
sh """
/kaniko/executor --context `pwd` --destination ngostal/golang:$COMMIT_ID
/kaniko/executor --context `pwd` --destination ngostal/golang:latest
"""
}
}
stage('Obtained the ArgoCD repository From GitHub') {
cleanWs()
git(
url: 'https://github.com/ngostal2019/ArgoCD-manifest.git',
branch: 'main',
changelog: true,
poll: true
)
container('jnlp') {
stage('Local Update of ArgoCD repository deployment file') {
sh """
ls -ltha
"""
def initDeployment = readFile 'overlays/dev/dev-deployment.yml'
deployment = initDeployment.replaceAll("image:.*", "image: ngostal/golang:$COMMIT_ID")
writeFile file: "overlays/dev/dev-deployment.yml", text: deployment
sh "cat overlays/dev/dev-deployment.yml"
}
}
}
stage('Update ArgoCD Deployment file on GitHub') {
container('jnlp') {
sh """
ls -ltha
git remote -v
git checkout -b hotfix/dev
git status
git add overlays/dev/dev-deployment.yml
git config --global user.name "Jenkins Server"
git config --global user.email "jenkins-server-${env.BUILD_ID}@hotmail.com"
git config --list | grep "user"
git commit -m "Updated dev-deployment.yml file from Jenkins CI."
"""
withCredentials([gitUsernamePassword(credentialsId: 'GITHUB_PASS', gitToolName: 'Default')]) {
sh 'git push -f origin hotfix/dev'
}
}
}
}