forked from Zulaikha12/git-test
-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathJenkins-DSL-Scripted-pipeline.txt
179 lines (139 loc) · 5.58 KB
/
Jenkins-DSL-Scripted-pipeline.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Jenkins Pipeline - google " getting started with jenkins pipeline"
Need pipeline plug-in
type of pipelines -
scripted - groovy like scripts
declarative - uses jenkinsfile
==============================================
Pre-requisite - Jenkins Stage view plugin should be installed.
----------------------------------------------
Jenkins Jobs using jenkinsfile
---------------------------------------------
First Job
New Item -> pipeline -> JenkinsPipelineDemo-1
Pipeline -> pipeline script from SCM (declarative pipeline)
GIT : https://github.com/puneetbhatia77/git-test.git
Script Path : Jenkinsfile.txt
----------------------------------------------------------------------------
Second Job
New Item -> pipeline -> Scripted Pipeline Demo -> JenkinsPipelineDemo-2-script
Pipeline -> pipeline script
node {
for (i=0; i<2; i++) {
stage "Stage #"+i
print 'Hello, world !'
if (i==0)
{
echo 'Running on Stage #0'
}
else {
build 'JenkinsPipelineDemo-1'
echo 'Running on Stage #1'
}
}
}
-----------------------------------------------------------------------------
Third Job
New Item -> pipeline -> JenkinsPipelineDemo-3
Pipeline -> pipeline script from SCM (declarative pipeline)
GIT : https://github.com/puneetbhatia77/git-test.git
Script Path : Jenkinsfile3.txt
----------------------------------------------------------------------------
Forth Job
New Item -> pipeline -> JenkinsPipelineDemo-4
Pipeline -> pipeline script from SCM (declarative pipeline)
GIT : https://github.com/puneetbhatia77/git-test.git
Script Path : Jenkinsfile4.txt
----------------------------------------------------------------------------
Fifth Job
New Item -> pipeline -> JenkinsPipelineDemo-5
Pipeline -> pipeline script from SCM (declarative pipeline)
GIT : https://github.com/puneetbhatia77/git-test.git
Script Path : Jenkinsfile5.txt
----------------------------------------------------------------------------
Docker
-----------------------------------------------------------
Test docker command in jenkins
-----------------------------------------------------------
# make sure docker is installed on VM and add jenkins user to docker group.
sudo usermod -aG docker jenkins # adding jenkins user to docker group
sudo usermod -aG docker vagrant # adding vagrant user to docker group (optional here)
# and then restart jenkins to take effect
First Job : jenkinsPipeline-dockerTest-demo1
build -> execute shell
docker run hello-world
--------------------------------------------------------------------------------
Sixth Job - Docker
New Item -> pipeline -> JenkinsPipelineDemoDocker
Pipeline -> pipeline script from SCM (declarative pipeline)
GIT : https://github.com/puneetbhatia77/git-test.git
Script Path : Jenkinsfile-docker.txt
pipeline {
agent any
stages {
stage('One') {
steps {
echo 'Hi, this is Puneet from DevOps'
}
}
stage('Two'){
steps {
input('Do you want to proceed?')
}
}
stage('Three') {
when {
not {
branch "master"
}
}
steps {
echo "Hello"
}
}
stage('Four') {
parallel {
stage('Unit Test') {
steps{
echo "Running the unit test..."
}
}
stage('Integration test') {
agent {
docker { # make sure docker is installed on VM and add jenkins user to docker group.
reuseNode false # sudo usermod -aG docker jenkins, adding jenkins user to docker group
image 'ubuntu' # sudo usermod -aG docker vagrant and then restart jenkins to take effect
} #reuseNode , a boolean, false by default. If true, run the container on the node specified at the top-level of the Pipeline,
} # in the same workspace, rather than on a new node entirely.
steps {
echo 'Running the integration test..'
}
} }
}
}
}
-------------------------------------------------------------------------------
Seventh Job - Docker Maven
New Item -> pipeline -> JenkinsPipelineDemoDocker-Maven
Pipeline -> pipeline script from SCM (declarative pipeline)
GIT : https://github.com/puneetbhatia77/git-test.git
Script Path : maven-jdk-hello
pipeline {
agent none
stages {
stage('Example Build') {
agent { docker 'maven:3-alpine' }
steps {
echo 'Hello, Maven'
sh 'mvn --version'
}
}
stage('Example Test') {
agent { docker 'openjdk:8-jre' } # can also be tested at terminal by tunning the command " sudo docker run -it openjdk:8-jre bash" and " java -version"
steps {
echo 'Hello, JDK'
sh 'java -version'
}
}
}
}
-------------------------------------------------