Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
parameters{
booleanParam(
defaultValue: false,
description: 'Skip deploy integ',
name: 'skip_deploy_integ'
)
booleanParam(
defaultValue: false,
description: 'Skip perf',
name: 'skip_perf'
)
booleanParam(
defaultValue: true,
description: 'Skip release',
name: 'skip_release'
)
booleanParam(
defaultValue: false,
description: 'Skip sonar',
name: 'skip_sonar'
)
booleanParam(
defaultValue: true,
description: 'Skip deploy preprod',
name: 'skip_deploy_preprod'
)
string(
defaultValue: '',
description: 'nouvelle version projet exemple : 0.0.1-SNAPSHOT',
name: 'newVersion'
)
environment {
sonar_host_url="http://192.168.1.77:29000/"
sonar_coverage_exclusions="**/*Representation.java,**/*Commande.java,**/*Query.java
,**/*Dto.java"
sonar_duplication_exclusions="**/*Representation.java,**/*Commande.java,**/*Query.j
ava,**/*Dto.java"
def release_version = getReleaseVersion()
options {
buildDiscarder(logRotator(numToKeepStr: '6', artifactNumToKeepStr: '6'))
}
triggers {
cron('H 01 * * 1-7')
}
stages {
stage ('Checkout Perf'){
steps{
sh 'ls -al'
sshagent(['robotops']) {
sh 'git clone git@gitlab.wafaassurance.co.ma:rs/api-rs-perf.git'
}
sh 'ls -al'
}
}
stage('Build api') {
steps{
//compilation
sh 'mvn -e -s /var/jenkins_home/mvn/settings.xml -gs
/var/jenkins_home/mvn/settings.xml -Dmaven.test.skip=true clean install -U'
//tests unitaires
sh 'mvn -e -s /var/jenkins_home/mvn/settings.xml -gs
/var/jenkins_home/mvn/settings.xml test -PTest-All'
junit(allowEmptyResults: true, testResults: '**/surefire-
reports/*.xml')
script {
if (params.skip_sonar == false) {
}
}
//déploiement nexus
sh 'mvn -e -s /var/jenkins_home/mvn/settings.xml -gs
/var/jenkins_home/mvn/settings.xml -Dmaven.test.skip=true deploy'
}
}
script {
def build_version = getCurrentVersion()
sh """ssh -i /var/jenkins_home/ssh_keys/id_rsa_root_87 -T -o
StrictHostKeyChecking=no root@192.168.1.87 << EOF
cd /etc/ansible
if [ ! -d "deploy" ] ; then
git clone
"git@gitlab.wafaassurance.co.ma:digitale/config/ansible.git" "deploy"
cd deploy
else
cd deploy
git pull
fi
cd /etc/ansible/deploy
exit
EOF"""
}
}
}
//Cucumber
sh 'mvn -e -s /var/jenkins_home/mvn/settings.xml -gs
/var/jenkins_home/mvn/settings.xml verify -PUAT -Dmaven.test.failure.ignore=true'
cucumber fileIncludePattern: 'target/cucumber-report/*.json',
sortingMethod: 'ALPHABETICAL'
script {
if (params.skip_sonar == false) {
//sonar api
sonar_exec('',null,null)
}
}
}
}
stage('Api Perf') {
when {
expression { params.skip_perf == false }
}
steps {
script {
try {
dir(path: 'api-rs-perf') {
sh 'pwd'
sh 'mvn -U -e -s /var/jenkins_home/mvn/settings.xml
-gs /var/jenkins_home/mvn/settings.xml clean install
-Dgatling.simulationClass=ma.wafaassurance.simulations.TarifRapideSimulation
-Dgatling.useOldJenkinsJUnitSupport=true'
}
}
catch (exc) {
}
}
gatlingArchive()
step([$class: 'JUnitResultArchiver', testResults:
'**/target/gatling/assertions-*.xml'])
}
}
}
}
stage('Release') {
when {
expression { params.skip_release == false }
}
steps{
script {
def new_version = getNewVersion()
sshagent(['robotops']) {
sh "git config --global user.email
robotops@wafaassurance.co.ma"
try{
sh "mvn -e -s /var/jenkins_home/mvn/settings.xml -gs
/var/jenkins_home/mvn/settings.xml release:clean release:prepare release:perform
-DreleaseVersion=${release_version}-Final -DdevelopmentVersion=${new_version}-
SNAPSHOT -DignoreSnapshots=true"
}catch(exc){
sh "mvn -e -s /var/jenkins_home/mvn/settings.xml -gs
/var/jenkins_home/mvn/settings.xml release:rollback"
throw new Exception(exc)
}
}
}
}
}
stage('Deploy preprod') {
when {
expression { params.skip_deploy_preprod == false }
}
steps {
echo "Pass ${currentVersion} to Preprod Stage"
sh """ssh -T -o StrictHostKeyChecking=no preprod@192.168.20.58 << EOF
cd /home/preprod
if [ ! -d "ansible" ] ; then
git clone
"git@gitlab.wafaassurance.co.ma:digitale/config/ansible.git" "ansible"
cd ansible
else
cd ansible
git pull
fi
cd /home/preprod
if [ ! -d "inventory" ] ; then
git clone
"git@gitlab.wafaassurance.co.ma:digitale/config/invontory-preprod.git" "inventory"
cd inventory
else
cd inventory
git pull
fi
cd /home/preprod/ansible
ansible-playbook -i /home/preprod/inventory/invontory -s
api/mrh/site.yml --extra-vars "mvn_repo_type=releases mvn_version=$
{release_version}-Final"
exit
EOF"""
}
}
stage('Clean') {
steps {
cleanWs()
}
}
}
tools {
maven 'apache-maven-3.5.2'
jdk 'jdk8'
}
def sonar_exec(sonar_branch,sonar_exclusions,sonar_inclusions) {
commande = "mvn -e -s /var/jenkins_home/mvn/settings.xml -gs
/var/jenkins_home/mvn/settings.xml sonar:sonar -Dsonar.host.url=${sonar_host_url}
-Dsonar.branch=${sonar_branch} -Dsonar.coverage.exclusions=$
{sonar_coverage_exclusions} -Dsonar.cpd.exclusions=${sonar_duplication_exclusions}"
if(sonar_exclusions!=null){
commande = commande + " -Dsonar.exclusions=${sonar_exclusions}"
}
if(sonar_inclusions!=null){
commande = commande + " -Dsonar.inclusions=${sonar_inclusions}"
}
try {
sh commande;
}
catch (exc) {
}
def getCurrentVersion(){
def getReleaseVersion(){
return getCurrentVersion().minus('-SNAPSHOT')
def getNewVersion(){
if(params.newVersion.trim() == ''){
def value = getReleaseVersion().tokenize('.')
//return value[0] + value[1] + value[2]++
def value1 = value[0]
def value2 = value[1]
def increment = value[2].toInteger()+1
return "${value1}.${value2}.${increment}"
}else {
return params.newVersion.trim()
}