forked from sathyadevops/mvnproj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkins_k8Deploy.txt
62 lines (56 loc) · 1.58 KB
/
Jenkins_k8Deploy.txt
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
#pipeline syntax
#git: Git
#withCredentials: Bind credentials to variables.
node{
stage("git clone"){
git credentialsId: 'GIT_CREDS', url: 'https://github.com/sathyadevops/mvnproj.git'
}
stage("clean comple"){
def mavenHome = tool name: "maven", type: "maven"
def mavenCMD = "${mavenHome}/bin/mvn"
sh "${mavenCMD} clean compile test package"
}
stage("docker build"){
sh "docker build -t sathyadevops/jenkins_k8image ."
}
stage("docker push"){
withCredentials([string(credentialsId: 'DOCKER_HUB_CREDS', variable: 'DOCKER_HUB_CREDS')]) {
sh "docker login -u sathyadevops -p ${DOCKER_HUB_CREDS}"
}
sh "docker push sathyadevops/jenkins_k8image"
}
}
===============================================================
pipeline{
agent any
environment {
VAR_DOCKER_HUB_CREDS = credentials('dockerhub-creds')
}
stages{
stage("git clone"){
steps{
git credentialsId: 'GIT_CREDS', url: 'https://github.com/sathyadevops/mvnproj.git'
}
}
//stage("clean comple"){
// steps{
// sh "/usr/bin/mvn clean compile test package"
// }
//}
stage("docker login"){
steps{
sh "echo $VAR_DOCKER_HUB_CREDS_PSW | docker login -u $VAR_DOCKER_HUB_CREDS_USR --password-stdin"
}
}
stage("docker build"){
steps{
sh "docker build -t sathyadevops/jenkins_k8image ."
}
}
stage("docker push"){
steps{
sh "docker push sathyadevops/jenkins_k8image"
}
}
}
}