pipeline {
  environment {
    registry = 'https://registry.hub.docker.com'
    registryCredential = 'dockerhub_jcabillot'
    dockerImage = 'jcabillot/jenkins-wdocker'
  }

  agent any

  stages {
    stage('Clone repository') {
      steps{
        checkout scm
      }
    }

    stage('Build image') {
      steps{
        sh "docker build -t jcabillot/jenkins-wdocker ."
      }
    }

    stage('Deploy Image') {
      steps{
        script {
          withDockerRegistry(url: 'https://docker.io', credentialsId: 'dockerhub_jcabillot') {
              sh 'docker push jcabillot/jenkins-wdocker'
            }
        }
      }
    }
  }
}
