Skip to content

Commit 8a56ae6

Browse files
Jaime Salas ZancadaJaime Salas Zancada
authored andcommitted
adding steps real pipeline
1 parent c50f87a commit 8a56ae6

File tree

4 files changed

+158
-3
lines changed

4 files changed

+158
-3
lines changed

03-cd/01-jenkins/02-construyendo-pipelines-reusables/00_clean_code_refactor_pipelines.md

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,154 @@ Eliminar las pipelines anteriores
88

99
Ejecutar Jenkins en Docker [Docker](https://www.docker.com/products/docker-desktop)
1010

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+

03-cd/01-jenkins/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Jenkins
2+
3+
## Repositorios relacionados
4+
5+
* [bootcamp-jenkins-demo](https://github.com/Lemoncode/bootcamp-jenkins-demo)

03-cd/01-jenkins/code/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

03-cd/01-jenkins/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)