Last active
May 27, 2019 06:01
-
-
Save hackerzhut/f1903fce06668172cd747071c2f79ad1 to your computer and use it in GitHub Desktop.
Sample Jenkinsfile to push docker image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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