@@ -22,7 +22,7 @@ Creamos `01/demo1/1.1/Jenkinsfile`
22
22
pipeline {
23
23
agent any
24
24
environment {
25
- VERSION = ""
25
+ VERSION = sh([ script: 'cd ./01/src && npm run env | grep "npm_package_version"', returnStdout: true ]).trim()
26
26
VERSION_RC = "rc.2"
27
27
}
28
28
stages {
@@ -38,12 +38,13 @@ pipeline {
38
38
}
39
39
stage('Build') {
40
40
steps {
41
- env.VERSION = sh([ script: 'npm run env | grep "npm_package_version"', returnStdout: true ]).trim()
42
- echo "Building version ${VERSION} with suffix: ${VERSION_RC}"
43
- sh '''
44
- npm install
45
- npm run build
46
- '''
41
+ dir('./01/src') {
42
+ echo "Building version ${VERSION} with suffix: ${VERSION_RC}"
43
+ sh '''
44
+ npm install
45
+ npm run build
46
+ '''
47
+ }
47
48
}
48
49
}
49
50
stage('Unit Test') {
@@ -57,13 +58,13 @@ pipeline {
57
58
}
58
59
```
59
60
60
- ## 1.1 Una pipeline que comeinza a hacer trabajo
61
+ ## 1.1 Una pipeline que comienza a hacer trabajo
61
62
62
63
Log into Jenkins at http://localhost:8080 with ` lemoncode ` /` lemoncode ` .
63
64
64
65
- New item, pipeline, ` demo1-1 `
65
66
- Select pipeline from source control
66
- - Git - https://github.com/JaimeSalas/jenkins-pipeline-demos.git
67
+ - Git - https://github.com/JaimeSalas/jenkins-pipeline-demos.git https://github.com/Lemoncode/bootcamp-jenkins-demo.git
67
68
- Path to Jenkinsfile - ` 01/demo1/1.1/Jenkinsfile `
68
69
- Open in Blue Ocean
69
70
- Run
@@ -81,7 +82,7 @@ pipeline {
81
82
}
82
83
/*diff*/
83
84
environment {
84
- VERSION = ""
85
+ VERSION = sh([ script: 'cd ./01/src && npm run env | grep "npm_package_version"', returnStdout: true ]).trim()
85
86
VERSION_RC = "rc.2"
86
87
}
87
88
stages {
@@ -102,13 +103,14 @@ pipeline {
102
103
}
103
104
/*diff*/
104
105
steps {
105
- env.VERSION = sh([ script: 'npm run env | grep "npm_package_version"', returnStdout: true ]).trim()
106
- // echo "Building version ${VERSION} with suffix: ${VERSION_RC}"
107
- echo "Building version ${VERSION} with suffix: ${VERSION_SUFFIX}"
108
- sh '''
109
- npm install
110
- npm run build
111
- '''
106
+ dir('./01/src') {
107
+ // echo "Building version ${VERSION} with suffix: ${VERSION_RC}"
108
+ echo "Building version ${VERSION} with suffix: ${VERSION_SUFFIX}"
109
+ sh '''
110
+ npm install
111
+ npm run build
112
+ '''
113
+ }
112
114
}
113
115
}
114
116
stage('Unit Test') {
@@ -118,14 +120,16 @@ pipeline {
118
120
}
119
121
}
120
122
}
123
+ /*diff*/
121
124
stage('Publish') {
122
125
when {
123
126
expression { return params.RC }
124
- steps {
125
- archiveArtifacts('app/')
126
- }
127
+ }
128
+ steps {
129
+ archiveArtifacts('01/src/app/')
127
130
}
128
131
}
132
+ /*diff*/
129
133
}
130
134
}
131
135
```
@@ -139,15 +143,15 @@ Push changes to remote repository
139
143
140
144
> Walk through the [ Jenkinsfile] ( ./1.2/Jenkinsfile )
141
145
142
- This is conditional stage, and only will run if ` RC ` parameter was set to true
146
+ Lo importanet es notar aquí, es este paso condicional que sólo se ejecutará si ` RC ` vale ** true** .
143
147
144
148
``` groovy
145
149
stage('Publish') {
146
150
when {
147
151
expression { return params.RC }
148
- steps {
149
- archiveArtifacts('app/')
150
- }
152
+ }
153
+ steps {
154
+ archiveArtifacts('01/src/app/')
151
155
}
152
156
}
153
157
```
@@ -159,3 +163,92 @@ stage('Publish') {
159
163
160
164
## 1.3 Usando métodos de Groovy
161
165
166
+ Crear ` 01/demo1/1.3/Jenkinsfile ` empezando desde el anterior y editandolo de la siguiente manera_
167
+
168
+ ``` diff
169
+ pipeline {
170
+ agent any
171
+ parameters {
172
+ booleanParam(name: 'RC', defaultValue: false, description: 'Is this a Release Candidate?')
173
+ }
174
+ environment {
175
+ VERSION = sh([ script: 'cd ./01/src && npm run env | grep "npm_package_version"', returnStdout: true ]).trim()
176
+ VERSION_RC = "rc.2"
177
+ }
178
+ stages {
179
+ stage('Audit tools') {
180
+ steps {
181
+ - sh '''
182
+ - git version
183
+ - docker version
184
+ - node --version
185
+ - npm version
186
+ - '''
187
+ + auditTools()
188
+ }
189
+ }
190
+ stage('Build') {
191
+ environment {
192
+ - VERSION_SUFFIX = "${sh(script:'if [ "${RC}" == "false" ] ; then echo -n "${VERSION_RC}+ci.${BUILD_NUMBER}"; else echo -n "${VERSION_RC}"; fi', returnStdout: true)}"
193
+ + VERSION_SUFFIX = getVersionSuffix()
194
+ }
195
+ steps {
196
+ dir('./01/src') {
197
+ echo "Building version ${VERSION} with suffix: ${VERSION_SUFFIX}"
198
+ sh '''
199
+ npm install
200
+ npm run build
201
+ '''
202
+ }
203
+ }
204
+ }
205
+ stage('Unit Test') {
206
+ steps {
207
+ dir('./01/src') {
208
+ sh 'npm test'
209
+ }
210
+ }
211
+ }
212
+ stage('Publish') {
213
+ when {
214
+ expression { return params.RC }
215
+ }
216
+ steps {
217
+ archiveArtifacts('01/src/app/')
218
+ }
219
+ }
220
+ }
221
+ }
222
+ +
223
+ + String getVersionSuffix() {
224
+ + if (params.RC) {
225
+ + return env.VERSION_RC
226
+ + } else {
227
+ + return env.VERSION_RC + '+ci' + env.BUILD_NUMBER
228
+ + }
229
+ + }
230
+ +
231
+ + void auditTools() {
232
+ + sh '''
233
+ + git version
234
+ + docker version
235
+ + node --version
236
+ + npm version
237
+ + '''
238
+ + }
239
+ ```
240
+
241
+ Push changes
242
+
243
+ - Copy item, ` demo1-3 ` from ` demo1-1 `
244
+ - Path to Jenkinsfile ` 01/demo1/1.3/Jenkinsfile `
245
+ - Build now
246
+ - Run
247
+
248
+ > Walk through the [ Jenkinsfile] ( ./1.3/Jenkinsfile )
249
+
250
+ - Open in Blue Ocean
251
+ - Run again - _ RC = no_
252
+ - Run again - _ RC = yes_
253
+
254
+ > Check logs and artifacts
0 commit comments