file-storage/Jenkinsfile

47 lines
1.6 KiB
Plaintext
Raw Normal View History

2018-11-23 12:23:28 +00:00
#!groovy
2018-12-04 12:24:35 +00:00
build('file-storage', 'java-maven') {
2018-11-23 12:23:28 +00:00
checkoutRepo()
2018-12-04 12:24:35 +00:00
def serviceName = env.REPO_NAME
def mvnArgs = '-DjvmArgs="-Xmx256m"'
2018-11-23 12:23:28 +00:00
2018-12-04 12:24:35 +00:00
// 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 'mvn deploy' + mvn_command_arguments
} else {
sh 'mvn package' + mvn_command_arguments
}
2018-11-23 12:23:28 +00:00
}
2018-12-04 12:24:35 +00:00
}
2018-11-23 12:23:28 +00:00
2018-12-04 12:24:35 +00:00
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') {
runStage('Push Service image') {
docker.withRegistry('https://dr.rbkmoney.com/v2/', 'dockerhub-rbkmoneycibot') {
serviceImage.push();
2018-11-23 12:23:28 +00:00
}
2018-12-04 12:24:35 +00:00
// Push under 'withRegistry' generates 2d record with 'long name' in local docker registry.
// Untag the long-name
sh "docker rmi dr.rbkmoney.com/${imgShortName}"
2018-11-23 12:23:28 +00:00
}
}
}
2018-12-04 12:24:35 +00:00
finally {
runStage('Remove local image') {
// Remove the image to keep Jenkins runner clean.
sh "docker rmi ${imgShortName}"
}
}
}