Skip to content
Permalink
Browse files

Commit inicial

  • Loading branch information
dmunozfer committed Jul 2, 2016
0 parents commit e732b2ea5ca5eba65fa8c4a9704906f9a81289a5
@@ -0,0 +1,82 @@

# Created by https://www.gitignore.io/api/java,eclipse,maven

### Eclipse ###

.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/


### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties


### Java ###
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
@@ -0,0 +1,53 @@
#!groovy

node {
// ------------------------------------
// -- ETAPA: Compilar
// ------------------------------------
stage 'Compilar'

// -- Configura variables
echo 'Configurando variables'
def mvnHome = tool 'M3'
env.PATH = "${mvnHome}/bin:${env.PATH}"
echo "var mvnHome='${mvnHome}'"
echo "var env.PATH='${env.PATH}'"

// -- Descarga código desde SCM
echo 'Descargando código de SCM'
sh 'rm -rf *'
git url: 'https://github.com/dmunozfer/dmunozfer.es-tutorial-jenkins-2.git'

// -- Compilando
echo 'Compilando aplicación'
sh 'mvn clean compile'

// ------------------------------------
// -- ETAPA: Test
// ------------------------------------
stage 'Test'
echo 'Ejecutando tests'
try{
sh 'mvn verify'
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
}catch(err) {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
if (currentBuild.result == 'UNSTABLE')
currentBuild.result = 'FAILURE'
throw err
}

// ------------------------------------
// -- ETAPA: Instalar
// ------------------------------------
stage 'Instalar'
echo 'Instala el paquete generado en el repositorio maven'
sh 'mvn install -Dmaven.test.skip=true'

// ------------------------------------
// -- ETAPA: Archivar
// ------------------------------------
stage 'Archivar'
echo 'Archiva el paquete el paquete generado en Jenkins'
step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar, **/target/*.war', fingerprint: true])
}
@@ -0,0 +1,9 @@
# Tutorial Jenkins 2 – Configuración pipeline


## Información
Este repositorio incluye la aplicación de ejemplo y la configuración el pipeline de Jenkis utilizado en el tutorial [Tutorial Jenkins 2 – Configuración pipeline](http://dmunozfer.es/tutorial-jenkins-2-configuracion-pipeline)

## Contenido del tutorial

En este tutorial aprenderemos los fundamentos de los pipelines de Jenkins y configuraremos uno sencillo en el que integraremos una aplicación **java con spring boot + maven + github**. El pipeline lo mantendremos en el propio repositorio de github y conectaremos Github con Jenkins mediante **hooks** de forma que cada vez que se realice un commit en el repositorio se ejecute de forma automática el pipeline de Jenkins.
49 pom.xml
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>es.dmunozfer</groupId>
<artifactId>tutorial-jenkins-2</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Tutorial Jenkins 2</name>
<description>Aplicación de ejemplo para el tutorial de Jenkins 2</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>
@@ -0,0 +1,12 @@
package es.dmunozfer.jenkins;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@@ -0,0 +1,22 @@
package es.dmunozfer.jenkins;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HolaController {

@RequestMapping("/")
public String raiz() {
return "redirect:/hola";
}

@RequestMapping("/hola")
public String hola(@RequestParam(value = "nombre", required = false, defaultValue = "Mundo") String nombre,
Model model) {
model.addAttribute("nombre", nombre);
return "hola";
}
}
Empty file.
@@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Probando Jenkins 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'¡Hola ' + ${nombre} + '!'">¡Hola Mundo!</p>
</body>
</html>
@@ -0,0 +1,61 @@
package es.dmunozfer.jenkins;

import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = DemoApplication.class)
@WebAppConfiguration
public class HolaControllerTest {

@Autowired
private WebApplicationContext webContext;
private MockMvc mockMvc;

@Before
public void setupMockMvc() {
mockMvc = MockMvcBuilders.webAppContextSetup(webContext).build();
}

@Test
public void raiz() throws Exception {
mockMvc.perform(get("/"))
.andExpect(status().is3xxRedirection())
.andExpect(header().string("Location", "/hola"));
}

@Test
public void holaSinParametros() throws Exception {
mockMvc.perform(get("/hola"))
.andExpect(status().isOk())
.andExpect(view().name("hola"))
.andExpect(model().attributeExists("nombre"))
.andExpect(model().attribute("nombre", is("Mundo")))
.andExpect(content().string(containsString("¡Hola Mundo!")))
;
}

@Test
public void holaDavid() throws Exception {
mockMvc.perform(get("/hola?nombre=David"))
.andExpect(status().isOk())
.andExpect(view().name("hola"))
.andExpect(model().attributeExists("nombre"))
.andExpect(model().attribute("nombre", is("David")))
.andExpect(content().string(containsString("¡Hola David!")))
;
}

}

0 comments on commit e732b2e

Please sign in to comment.
You can’t perform that action at this time.