-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
96 lines (80 loc) · 3.14 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
pipeline {
agent none
environment{
GITHUB_CRED = credentials('gitlab-cre')
}
stages {
stage('build image') {
agent { label 'docker'}
steps {
script{
def scmVars = checkout scm
stash name: 'source', includes: '**/*'
sh 'ls -altr'
sh 'docker build -t yassinebd/testphp:v1.1.9 .'
}
}
}
stage('change manifest') {
agent { label 'docker'}
steps {
script{
sh 'ls -altr'
sh 'sed -i "s/v1.0.5/v1.1.9/g" deployementtest.yaml'
sh 'cat deployementtest.yaml'
}
}
}
stage('push to Dockerhub')
{
agent { label 'docker'}
steps{
script{
unstash 'source'
withDockerRegistry([ credentialsId: "dockerhub_cred", url: "https://index.docker.io/v1/" ]) {
sh "docker push yassinebd/testphp:v1.1.9"
}
}
}
}
stage('push to gitlab'){
agent { label 'docker'}
steps{
script{
unstash 'source'
sh 'ls -altr'
sh 'git config --global user.name "byassine"'
sh 'git config --global user.email "[email protected]"'
sh "git config --global http.proxy http://10.97.243.181:808"
sh "git config --global https.proxy http://10.97.243.181:808"
sh 'mkdir -p manifest/manifest'
sh 'cp deployementtest.yaml manifest/manifest/deployment.yaml'
sh 'cat deployementtest.yaml'
dir('manifest') {
sh 'ls -altr'
sh "git remote rm origin"
sh 'rm -rf .git'
sh 'git init -b main'
sh "git remote add origin http://${GITHUB_CRED_USR}:${GITHUB_CRED_PSW}@10.97.232.172:7000/pocmanager/gitlab-cicd-project.git"
sh 'git add .'
sh 'git commit -m "Initial commit"'
sh 'git push -u origin main --force'
}
}
}
}
stage('deploy to k8s')
{
agent { label 'k8s_cli'}
steps{
git branch: 'main', changelog: false, poll: false, url: 'https://github.com/byassine/manifesttest.git'
script{
kubeconfig(credentialsId: 'k8s-kube', serverUrl: '') {
sh 'kubectl create ns jenkins || echo "namespace already exists"'
sh 'kubectl apply -f manifest/deployment.yaml'
}
}
}
}
}
}