node {
  checkout scm
  docker.image('teracy/angular-cli').inside() {
            stage('build'){
                sh 'npm config set registry http://registry.npm.taobao.org/'
                sh 'npm install'
                sh 'ng build'
            }
  }


   def imagesName = '130.120.3.193/com.gzzn.omms/admin-web:0.0.1-SNAPSHOT'
   stage('Image Build And Push'){
        docker.withRegistry('http://130.120.3.193', 'privateDockerId') {
              docker.build(imagesName).push()
        }
   }



   stage('deploy'){
               def remote = [:]
               remote.name = "airport-dev"
               remote.host = "130.120.3.231"
               remote.allowAnyHosts = true

               withCredentials([sshUserPrivateKey(credentialsId: 'e41b57a4-436a-4617-817c-9e3f25a8a47f', keyFileVariable: 'kfIdentity', passphraseVariable: 'pVariable', usernameVariable: 'userName')]) {
                 remote.user = userName
                 remote.identityFile = kfIdentity
                 
                 sshCommand remote: remote, command: "docker stop adminweb",sudo: true ,failOnError: false
                 sshCommand remote: remote, command: "docker rm adminweb",sudo: true ,failOnError: false
                 sshCommand remote: remote, command: "docker rmi 130.120.3.193/com.gzzn.omms/admin-web:0.0.1-SNAPSHOT",sudo: true ,failOnError: false
                 sshCommand remote: remote, command: "docker run -d -p 96:80 --name adminweb 130.120.3.193/com.gzzn.omms/admin-web:0.0.1-SNAPSHOT",sudo: true
               }
            }
}