-
Notifications
You must be signed in to change notification settings - Fork 189
/
Jenkinsfile-ScriptedTobeCopyPastedDirectly.txt
73 lines (69 loc) · 2.47 KB
/
Jenkinsfile-ScriptedTobeCopyPastedDirectly.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
63
64
65
66
67
68
69
70
71
72
73
pipeline {
agent any
stages {
stage ('Git-Checkout') {
steps{
git url: 'https://github.com/vilasvarghese/docker-k8s.git'
//credentialsId: 'myrandomid like e6757c46-0750-4ab1-8cd4-c569efcbbdb1',
echo "Checkout successful";
}
}
stage ('Compile') {
steps{
//bat label: '', script: 'mvn compile'
sh 'mvn compile'
echo "test successful";
}
}
stage ('Build') {
steps{
sh 'mvn clean'
sh 'mvn package'
echo "build successful";
}
}
stage ('Test') {
steps{
sh 'mvn test'
echo "test successful";
}
}
stage ('Create Docker Image') {
steps{
sh 'docker build -t java-web-app-cicd:latest .'
}
}
stage ('Integration Test') {
steps{
//ideally from a different repo.
sh 'mvn test'
}
}
stage ('Push docker image to Docker Hub') {
steps{
//Install Docker plugin and Docker Pipeline before executing this
/*
Go to credentials > System > Global credentials > Add credentials a page will open.
In Kind drop-down select Username and password.
In User put a non-existing username like jenkins-user or user.
Add Personal Access Token from DockerHub in the password field
*/
withCredentials([usernamePassword(credentialsId: 'dockerhub-username-accesstoken', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}"
sh 'docker push vilasvarghese/java-web-app-cicd:latest'
}
}
}
stage ('Deploy') {
steps{
sh '/usr/local/bin/kubectl delete deploy --all'
sh '/usr/local/bin/kubectl create -f deploy-tomcat.yaml'
}
}
stage ('Monitor') {
steps{
echo "Now you can monitor!";
}
}
}
}