pipeline{
agent any
environment{
registry = "ske04186/hello_world"
registryCredential = "docker-hub"
dockerImage = ''
}
stages{
stage('GIT-Checkout'){
steps{
checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/rodom1018/github-to-docker-practice.git']]])
}
}
stage('give superuser'){
steps{
script{
sh 'sudo -s'
sh 'sudo chmod 666 /var/run/docker.sock'
}
}
}
stage('build docker image'){
steps{
script{
sh 'docker build -t my-image:0.0.${BUILD_NUMBER} .'
}
}
}
stage('push image to docker hub'){
steps{
script{
withCredentials([string(credentialsId: 'dockerhub-pwd', variable: 'dockerpwd')]) {
// some block
sh 'docker login -u ske04186 -p ${dockerpwd}'
}
sh 'docker tag my-image:0.0.${BUILD_NUMBER} ske04186/hello_world:0.0.${BUILD_NUMBER}'
sh 'docker push ske04186/hello_world:0.0.${BUILD_NUMBER}'
}
}
}
}
}