-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
67 lines (55 loc) · 1.6 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
pipeline {
agent {
kubernetes {
defaultContainer 'jnlp'
yamlFile 'build.yaml'
}
}
stages {
stage('Lint') {
steps {
container(name: 'linter') {
sh 'apt-get update && apt-get install -y tidy && cd sample-app && tidy -q -e *.html'
}
}
}
stage('Docker Build') {
steps {
container(name: 'docker') {
sh "cd sample-app && docker build -t ${REGISTRY}:$GIT_COMMIT ."
}
}
}
stage('Docker push') {
steps {
container(name: 'docker') {
withCredentials([usernamePassword(credentialsId: "${REGISTRY_CREDENTIAL}", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "docker login -u $USERNAME -p $PASSWORD && docker push ${REGISTRY}:$GIT_COMMIT"
}
}
}
}
// NOTE: this did not work, maybe I did not use right url,
// also tried with url:"" , but jenkis compained if url was not set
// stage('Docker Publish') {
// steps {
// container(name: 'docker') {
// withDockerRegistry(credentialsId: "${REGISTRY_CREDENTIAL}", url: 'https://registry-1.docker.io/v2/') {
// sh "docker push ${REGISTRY}:$GIT_COMMIT"
// }
// }
// }
// }
stage('Kubernetes Deploy') {
steps {
container(name: 'kubectl') {
sh "sed -e 's|${REGISTRY}|${REGISTRY}:$GIT_COMMIT|g' sample-app/deploy-manifest.yaml | kubectl apply -f -"
}
}
}
}
environment {
REGISTRY = 'wideblue/udacity-microservice'
REGISTRY_CREDENTIAL = 'dockerhub-wideblue'
}
}