Files
airport-chengdu-web/jenkins/Jenkinsfile
T

44 lines
1.8 KiB
Groovy
Raw Normal View History

2018-11-06 14:09:43 +08:00
node {
2018-11-07 10:58:19 +08:00
def mailto="601470458@qq.com,505127606@qq.com,154707516@qq.com,444949396@qq.com,714943302@qq.com" //邮件接收人员列表
def containerName="adminweb" //容器名称
def imageName="130.120.3.193/com.gzzn.omms/admin-web:0.0.1-SNAPSHOT" //镜像名称
def dockerRegistry="http://130.120.3.193"
def credentialsId="e41b57a4-436a-4617-817c-9e3f25a8a47f" //ssh证书id
def deployHost="130.120.3.231" //发布到的主机
2018-11-06 14:09:43 +08:00
checkout scm
2018-11-06 15:25:21 +08:00
docker.image('teracy/angular-cli').inside() {
2018-11-06 14:09:43 +08:00
stage('build'){
2018-11-06 15:25:21 +08:00
sh 'npm config set registry http://registry.npm.taobao.org/'
2018-11-06 14:09:43 +08:00
sh 'npm install'
sh 'ng build'
}
}
stage('Image Build And Push'){
2018-11-07 10:58:19 +08:00
docker.withRegistry("${dockerRegistry}", 'privateDockerId') {
docker.build("${imageName}").push()
2018-11-06 14:09:43 +08:00
}
}
stage('deploy'){
2018-11-06 15:09:45 +08:00
def remote = [:]
2018-11-06 15:25:21 +08:00
remote.name = "airport-dev"
2018-11-07 10:58:19 +08:00
remote.host = "${deployHost}"
2018-11-06 14:09:43 +08:00
remote.allowAnyHosts = true
2018-11-07 10:58:19 +08:00
withCredentials([sshUserPrivateKey(credentialsId: "${credentialsId}", keyFileVariable: 'kfIdentity', passphraseVariable: 'pVariable', usernameVariable: 'userName')]) {
2018-11-06 14:09:43 +08:00
remote.user = userName
remote.identityFile = kfIdentity
2018-11-07 10:58:19 +08:00
sshCommand remote: remote, command: "docker stop ${containerName}",sudo: true ,failOnError: false
sshCommand remote: remote, command: "docker rm ${containerName}",sudo: true ,failOnError: false
sshCommand remote: remote, command: "docker rmi ${imageName}",sudo: true ,failOnError: false
sshCommand remote: remote, command: "docker run -d -p 96:80 --name ${containerName} ${imageName}",sudo: true
2018-11-06 14:09:43 +08:00
}
}
}