Skip to content

Instantly share code, notes, and snippets.

@hackerzhut
Last active May 27, 2019 06:01
Show Gist options
  • Save hackerzhut/f1903fce06668172cd747071c2f79ad1 to your computer and use it in GitHub Desktop.
Save hackerzhut/f1903fce06668172cd747071c2f79ad1 to your computer and use it in GitHub Desktop.
Sample Jenkinsfile to push docker image
def image = ''
def registry = ''
node('slaves'){
stage('Checkout'){
checkout scm
}
stage('Build'){
docker.build(image)
}
stage('Push'){
docker.withRegistry(registry, 'registry') {
docker.image(image).push("${commitID()}")
if (env.BRANCH_NAME == 'master') {
docker.image(image).push('latest')
}
}
}
stage('Deploy'){
build job: "oneshot-app-deployment"
}
}
def commitID() {
sh 'git rev-parse HEAD > .git/commitID'
def commitID = readFile('.git/commitID').trim()
sh 'rm .git/commitID'
commitID
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment