Created
August 6, 2020 20:18
-
-
Save ismailyenigul/4a89ac1297b6263d77244421aab87c53 to your computer and use it in GitHub Desktop.
sample Jenkinsfile declarative pipeline to build/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
pipeline { | |
environment { | |
imagename = "yenigul/hacicenkins" | |
registryCredential = 'yenigul-dockerhub' | |
dockerImage = '' | |
} | |
agent any | |
stages { | |
stage('Cloning Git') { | |
steps { | |
git([url: 'https://github.com/ismailyenigul/hacicenkins.git', branch: 'master', credentialsId: 'ismailyenigul-github-user-token']) | |
} | |
} | |
stage('Building image') { | |
steps{ | |
script { | |
dockerImage = docker.build imagename | |
} | |
} | |
} | |
stage('Deploy Image') { | |
steps{ | |
script { | |
docker.withRegistry( '', registryCredential ) { | |
dockerImage.push("$BUILD_NUMBER") | |
dockerImage.push('latest') | |
} | |
} | |
} | |
} | |
stage('Remove Unused docker image') { | |
steps{ | |
sh "docker rmi $imagename:$BUILD_NUMBER" | |
sh "docker rmi $imagename:latest" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment