mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-18 05:25:50 +00:00
Ajout pom.xml et Jenkinsfile
This commit is contained in:
parent
7961e44714
commit
9c7d368e76
2 changed files with 170 additions and 1 deletions
115
Jenkinsfile
vendored
Normal file
115
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
node {
|
||||||
|
// Compilation
|
||||||
|
stage 'Compile'
|
||||||
|
|
||||||
|
echo 'toto'
|
||||||
|
checkout scm
|
||||||
|
|
||||||
|
sh "ls ${workspace}"
|
||||||
|
|
||||||
|
def v = version()
|
||||||
|
if (v) {
|
||||||
|
echo "Building version ${v}"
|
||||||
|
}
|
||||||
|
|
||||||
|
def mvnHome = tool 'M3'
|
||||||
|
sh "${mvnHome}/bin/mvn compile"
|
||||||
|
//archiveArtifacts artifacts: '**/target/classes/**', fingerprint: true
|
||||||
|
stash includes: '**/target/classes/**', name: 'ClassesFromCompileStage'
|
||||||
|
stash includes: '**/src/test/**', name: 'SourcesTestsFromCompileStage'
|
||||||
|
stash includes: 'pom.xml', name: 'Pom'
|
||||||
|
|
||||||
|
// Tests unitaires sequentiels
|
||||||
|
//stage 'TestU'
|
||||||
|
|
||||||
|
//sh "${mvnHome}/bin/mvn test"
|
||||||
|
//junit '**/target/surefire-reports/TEST-*.xml'
|
||||||
|
|
||||||
|
// Sonar
|
||||||
|
stage 'Quality'
|
||||||
|
|
||||||
|
sh '''
|
||||||
|
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
|
||||||
|
SONAR_BRANCH=`printf '%s' $GIT_BRANCH | sed s/[^0-9a-zA-Z:_.\\-]/'_'/g`
|
||||||
|
echo "GIT_BRANCH=${GIT_BRANCH}" > my-build-vars.properties
|
||||||
|
echo "SONAR_BRANCH=${SONAR_BRANCH}" >> my-build-vars.properties
|
||||||
|
'''
|
||||||
|
def props = getBuildProperties("my-build-vars.properties")
|
||||||
|
echo "my-build-vars.properties=${props}"
|
||||||
|
def sonarBranchParam = getSonarBranchParameter(props.getProperty('SONAR_BRANCH'))
|
||||||
|
|
||||||
|
sh "${mvnHome}/bin/mvn sonar:sonar ${sonarBranchParam} -Dsonar.exclusions=**/vendors/**,**/tests/**,**/test/** -Dsonar.jdbc.url='jdbc:h2:tcp://localhost:9092;databaseName=sonar' -Dsonar.host.url='http://localhost:9000' -Dsonar.jdbc.username=sonar -Dsonar.jdbc.password=sonar"
|
||||||
|
|
||||||
|
// Tests unitaires parallelises
|
||||||
|
stage 'Unit Tests'
|
||||||
|
runTests()
|
||||||
|
|
||||||
|
stage 'Package'
|
||||||
|
sh "${mvnHome}/bin/mvn package -DskipTests=true"
|
||||||
|
//archiveArtifacts artifacts: '**/target/classes/**', fingerprint: true
|
||||||
|
|
||||||
|
stage 'Deploy'
|
||||||
|
sh "${mvnHome}/bin/mvn tomcat7:deploy-only -DskipTests=true -Dmaven.tomcat.charset='UTF-8' -Dmaven.tomcat.path='/petclinic' -Dmaven.tomcat.update=true -Dmaven.tomcat.url='http://localhost:9966/manager/text' -DwarFile='${workspacePwd}/target/petclinic.war'"
|
||||||
|
|
||||||
|
input 'Is it ok ?'
|
||||||
|
sh "${mvnHome}/bin/mvn tomcat7:undeploy -DskipTests=true -Dmaven.tomcat.path='/petclinic' -Dmaven.tomcat.url='http://localhost:9966/manager/text'"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Joue les tests de maniere parallele
|
||||||
|
def runTests() {
|
||||||
|
|
||||||
|
def mvnHome = tool 'M3'
|
||||||
|
def splits = splitTests count(2)
|
||||||
|
def testGroups = [:]
|
||||||
|
for (int i = 0; i < splits.size(); i++) {
|
||||||
|
//def split = splits[i]
|
||||||
|
def index = i
|
||||||
|
testGroups["split${i}"] = {
|
||||||
|
node {
|
||||||
|
unstash 'ClassesFromCompileStage'
|
||||||
|
unstash 'SourcesTestsFromCompileStage'
|
||||||
|
unstash 'Pom'
|
||||||
|
|
||||||
|
sh "echo ${i}-${workspace}"
|
||||||
|
sh "ls ${workspace}"
|
||||||
|
|
||||||
|
def exclusions = splits.get(index);
|
||||||
|
writeFile file: 'exclusions.txt', text: exclusions.join("\n")
|
||||||
|
|
||||||
|
sh "ls ${workspace}"
|
||||||
|
|
||||||
|
def mavenTest = 'test -DMaven.test.failure.ignore=true -Pexclusions'
|
||||||
|
sh "${mvnHome}/bin/mvn ${mavenTest}"
|
||||||
|
|
||||||
|
junit '**/target/surefire-reports/TEST-*.xml'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parallel testGroups
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methodes utilitaires pour Maven
|
||||||
|
def version() {
|
||||||
|
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
|
||||||
|
matcher ? matcher[0][1] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methodes utilitaires pour Sonar
|
||||||
|
def getSonarBranchParameter(branch) {
|
||||||
|
sonarBranchParam = ""
|
||||||
|
if ("develop".equals(branch)) {
|
||||||
|
echo "branch is develop, sonar.branch not mandatory"
|
||||||
|
} else {
|
||||||
|
echo "branch is not develop"
|
||||||
|
sonarBranchParam="-Dsonar.branch=" + branch
|
||||||
|
}
|
||||||
|
return sonarBranchParam
|
||||||
|
}
|
||||||
|
|
||||||
|
def Properties getBuildProperties(filename) {
|
||||||
|
def properties = new Properties()
|
||||||
|
properties.load(new StringReader(readFile(filename)))
|
||||||
|
return properties
|
||||||
|
}
|
||||||
|
|
54
pom.xml
54
pom.xml
|
@ -325,6 +325,8 @@
|
||||||
<server>tomcat-development-server</server>
|
<server>tomcat-development-server</server>
|
||||||
<port>9966</port>
|
<port>9966</port>
|
||||||
<path>/petclinic</path>
|
<path>/petclinic</path>
|
||||||
|
<username>admin</username>
|
||||||
|
<password>password</password>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -442,6 +444,58 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</profile>
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<!-- if ./exclusions.txt is present, use that as the exclusion list. Useful when skipping tests. -->
|
||||||
|
<id>exclusions</id>
|
||||||
|
<activation>
|
||||||
|
<file>
|
||||||
|
<exists>exclusions.txt</exists>
|
||||||
|
</file>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludesFile>exclusions.txt</excludesFile>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hsqldb</groupId>
|
||||||
|
<artifactId>hsqldb</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<!-- if ./inclusions.txt is present, use that as the inclusion list. Useful when skipping tests. -->
|
||||||
|
<id>inclusions</id>
|
||||||
|
<activation>
|
||||||
|
<file>
|
||||||
|
<exists>inclusions.txt</exists>
|
||||||
|
</file>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<includesFile>inclusions.txt</includesFile>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hsqldb</groupId>
|
||||||
|
<artifactId>hsqldb</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<url>demopetclinic</url>
|
<url>demopetclinic</url>
|
||||||
|
|
Loading…
Reference in a new issue