Skip to content

Instantly share code, notes, and snippets.

@rgielen
Last active May 15, 2021 16:25
Show Gist options
  • Save rgielen/e8a6ff47d612dd74581c606e700cf3ae to your computer and use it in GitHub Desktop.
Save rgielen/e8a6ff47d612dd74581c606e700cf3ae to your computer and use it in GitHub Desktop.
Maven Build and Docker Push Jenkinsfile
node {
properties([
parameters([
string(name: 'dockerRegistry',
defaultValue: 'registry.hub.docker.com',
description: 'The docker registry to use (DNS name only)',),
string(name: 'dockerRepository',
defaultValue: 'apache/struts-showcase',
description: 'The repository to push to',),
string(name: 'dockerRegistryCredentialsId',
defaultValue: 'dockerhub-struts-credentials',
description: 'The Jenkins credentials id for docker registry to use',)
])
])
stage('Checkout') {
checkout scm
}
docker.image('maven:3.6.1-jdk-8').inside {
withMaven() {
stage('Maven Build') {
sh '"$MVN_CMD" clean package'
}
stage('Maven Deploy') {
sh '"$MVN_CMD" -DskipTests deploy'
}
}
}
docker.withRegistry("https://${dockerRegistry}", "${dockerRegistryCredentialsId}") {
stage('Docker Build') {
image = docker.build("${dockerRegistry}/$(dockerRepository)", "--pull --no-cache .")
}
stage('Docker Push') {
image.push()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment