Jenkins pipeline
node {
def SONAR = tool "${SONAR_VERSION}";
def MAVEN = tool "${MAVEN_VERSION}";
def MAVEN_SH = "${MAVEN}/bin/MAVEN";
def BUILD_MAVEN = 'pom.xml';
def PROXY = "";
dir(HOMEWORK) {
stage('GET_CODE') {
echo "[EXEC] - Obtener código fuente desde repositorio Git"
checkout([
$class: 'GitSCM',
branches: [[name: "${SCM_BRANCH}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: "${HOMEWORK}"
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: "${SCM_CREDENTIALS}",
url: "${SCM_URL}"
]]
]);
}
stage('BUILD_CODE') {
echo "[EXEC] - Compilación de código fuente - MAVEN '${HOMEWORK}/${BUILD_MAVEN}'";
withMaven(maven: "${MAVEN_VERSION}") {
sh "mvn package -Dmaven.test.skip=true -X"
}
}
stage('UNIT_TEST') {
echo "[EXEC] - Ejecución de pruebas unitarias."
withMaven(maven: "${MAVEN_VERSION}") {
sh "mvn test"
}
}
stage('CODE_ANA') {
echo "[EXEC] - Análisis estático de código"
sh "${SONAR}/bin/sonar-scanner -e -Dsonar.login=${SONAR_TOKEN} -Dsonar.host.url=${SONAR_URL} -Dproject.settings=${SONAR_PROP}"
}
stage('ARTIFACT_UP') {
echo "[EXEC] - Almacenando artefactos en Artifactory Server"
def server = Artifactory.server "${ARTIFACTORY_SERVER}"
def uploadSpec = """
{
"files": [
{
"pattern": "${ARTIFACTORY_PATTERN}",
"target": "${ARTIFACTORY_REPO}"
}
]
}
"""
def buildInfo1 = server.upload spec: uploadSpec
server.publishBuildInfo buildInfo1
}
}
}