@@ -8,4 +8,154 @@ Eliminar las pipelines anteriores
8
8
9
9
Ejecutar Jenkins en Docker [ Docker] ( https://www.docker.com/products/docker-desktop )
10
10
11
- Crear un nuevo directorio * src_tmp/jenkins-demos-review/01* . ` unzip ` code from
11
+ Crear un nuevo directorio * src_tmp/jenkins-demos-review/01* . ` unzip ` del fichero ` 01-jenkins/code.zip `
12
+
13
+ ``` bash
14
+ $ unzip code.zip -d ./src_temp/jenkins-demos-review/01
15
+ ```
16
+
17
+ Hacemos ` push ` de los cambios al repositorio remoto
18
+
19
+ Creamos ` 01/demo1/1.1/Jenkinsfile `
20
+
21
+ ``` groovy
22
+ pipeline {
23
+ agent any
24
+ environment {
25
+ VERSION = ""
26
+ VERSION_RC = "rc.2"
27
+ }
28
+ stages {
29
+ stage('Audit tools') {
30
+ steps {
31
+ sh '''
32
+ git version
33
+ docker version
34
+ node --version
35
+ npm version
36
+ '''
37
+ }
38
+ }
39
+ stage('Build') {
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
+ '''
47
+ }
48
+ }
49
+ stage('Unit Test') {
50
+ steps {
51
+ dir('./01/src') {
52
+ sh 'npm test'
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## 1.1 Una pipeline que comeinza a hacer trabajo
61
+
62
+ Log into Jenkins at http://localhost:8080 with ` lemoncode ` /` lemoncode ` .
63
+
64
+ - New item, pipeline, ` demo1-1 `
65
+ - Select pipeline from source control
66
+ - Git - https://github.com/JaimeSalas/jenkins-pipeline-demos.git
67
+ - Path to Jenkinsfile - ` 01/demo1/1.1/Jenkinsfile `
68
+ - Open in Blue Ocean
69
+ - Run
70
+
71
+ > Walk through the [ Jenkinsfile] ( ./1.1/Jenkinsfile )
72
+
73
+ ## 1.2 Añadiendo parámetros para la build RC
74
+
75
+ ``` groovy
76
+ pipeline {
77
+ agent any
78
+ /*diff*/
79
+ parameters {
80
+ booleanParam(name: 'RC', defaultValue: false, description: 'Is this a Release Candidate?')
81
+ }
82
+ /*diff*/
83
+ environment {
84
+ VERSION = ""
85
+ VERSION_RC = "rc.2"
86
+ }
87
+ stages {
88
+ stage('Audit tools') {
89
+ steps {
90
+ sh '''
91
+ git version
92
+ docker version
93
+ node --version
94
+ npm version
95
+ '''
96
+ }
97
+ }
98
+ stage('Build') {
99
+ /*diff*/
100
+ environment {
101
+ VERSION_SUFFIX = "${sh(script:'if [ "${RC}" == "false" ] ; then echo -n "${VERSION_RC}+ci.${BUILD_NUMBER}"; else echo -n "${VERSION_RC}"; fi', returnStdout: true)}"
102
+ }
103
+ /*diff*/
104
+ 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
+ '''
112
+ }
113
+ }
114
+ stage('Unit Test') {
115
+ steps {
116
+ dir('./01/src') {
117
+ sh 'npm test'
118
+ }
119
+ }
120
+ }
121
+ stage('Publish') {
122
+ when {
123
+ expression { return params.RC }
124
+ steps {
125
+ archiveArtifacts('app/')
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ Push changes to remote repository
134
+
135
+ - Copy item, ` demo1-2 ` from ` demo1-1 `
136
+ - Path to Jenkinsfile ` 01/demo1/1.2/Jenkinsfile `
137
+ - Open in Blue Ocean
138
+ - Run (first build doesn't show option)
139
+
140
+ > Walk through the [ Jenkinsfile] ( ./1.2/Jenkinsfile )
141
+
142
+ This is conditional stage, and only will run if ` RC ` parameter was set to true
143
+
144
+ ``` groovy
145
+ stage('Publish') {
146
+ when {
147
+ expression { return params.RC }
148
+ steps {
149
+ archiveArtifacts('app/')
150
+ }
151
+ }
152
+ }
153
+ ```
154
+
155
+ - Run again - _ RC = no_
156
+ - Run again - _ RC = yes_
157
+
158
+ > Check logs and artifacts
159
+
160
+ ## 1.3 Usando métodos de Groovy
161
+
0 commit comments