Skip to content

Instantly share code, notes, and snippets.

@ismailyenigul
Created August 6, 2020 20:18
Show Gist options
  • Save ismailyenigul/4a89ac1297b6263d77244421aab87c53 to your computer and use it in GitHub Desktop.
Save ismailyenigul/4a89ac1297b6263d77244421aab87c53 to your computer and use it in GitHub Desktop.
sample Jenkinsfile declarative pipeline to build/push docker image
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