newway/Jenkinsfile
Baikov Dmitrii da9ada3132
PROX-264: Revision of the service. Changing the way source files are generated (#34)
* PROX-264: Revision of the service. Changing the way source files are generated
2019-01-10 19:49:37 +03:00

49 lines
1.8 KiB
Groovy

#!groovy
build('newway', 'java-maven') {
checkoutRepo()
env.JAVA_HOME = "JAVA_HOME=/opt/openjdk-bin-11.0.1_p13 "
def serviceName = env.REPO_NAME
def baseImageTag = "f26fcc19d1941ab74f1c72dd8a408be17a769333"
def mvnArgs = '-DjvmArgs="-Xmx256m"'
// Run mvn and generate docker file
runStage('Maven package') {
withCredentials([[$class: 'FileBinding', credentialsId: 'java-maven-settings.xml', variable: 'SETTINGS_XML']]) {
def mvn_command_arguments = ' --batch-mode --settings $SETTINGS_XML -P ci ' +
" -Dgit.branch=${env.BRANCH_NAME} " +
" ${mvnArgs}"
if (env.BRANCH_NAME == 'master') {
sh env.JAVA_HOME + 'mvn deploy' + mvn_command_arguments
} else {
sh env.JAVA_HOME + 'mvn package' + mvn_command_arguments
}
}
}
def serviceImage;
def imgShortName = 'rbkmoney/' + "${serviceName}" + ':' + '$COMMIT_ID';
getCommitId()
runStage('Build Service image') {
serviceImage = docker.build(imgShortName, '-f ./target/Dockerfile ./target')
}
try {
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME.startsWith('epic')) {
runStage('Push Service image') {
docker.withRegistry('https://dr.rbkmoney.com/v2/', 'dockerhub-rbkmoneycibot') {
serviceImage.push();
}
// Push under 'withRegistry' generates 2d record with 'long name' in local docker registry.
// Untag the long-name
sh "docker rmi dr.rbkmoney.com/${imgShortName}"
}
}
}
finally {
runStage('Remove local image') {
// Remove the image to keep Jenkins runner clean.
sh "docker rmi ${imgShortName}"
}
}
}