增加邮件发送功能

This commit is contained in:
zhouxiunai
2018-11-07 11:00:09 +08:00
parent 3c7cbd11ad
commit e95dd9d401
+67 -33
View File
@@ -6,39 +6,73 @@ node {
def credentialsId="e41b57a4-436a-4617-817c-9e3f25a8a47f" //ssh证书id
def deployHost="130.120.3.231" //发布到的主机
try
{
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'
}
}
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'
}
stage('Image Build And Push'){
docker.withRegistry("${dockerRegistry}", 'privateDockerId') {
docker.build("${imageName}").push()
}
}
stage('deploy'){
def remote = [:]
remote.name = "airport-dev"
remote.host = "${deployHost}"
remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(credentialsId: "${credentialsId}", keyFileVariable: 'kfIdentity', passphraseVariable: 'pVariable', usernameVariable: 'userName')]) {
remote.user = userName
remote.identityFile = kfIdentity
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
}
}
//发送邮件
emailext (
subject: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' 更新正常",
body: """
详情:
SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'
状态:${env.JOB_NAME} jenkins 更新运行正常
URL ${env.BUILD_URL}
项目名称 ${env.JOB_NAME}
项目更新进度:${env.BUILD_NUMBER}
""",
to: "${mailto}",
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)
}
stage('Image Build And Push'){
docker.withRegistry("${dockerRegistry}", 'privateDockerId') {
docker.build("${imageName}").push()
}
}
stage('deploy'){
def remote = [:]
remote.name = "airport-dev"
remote.host = "${deployHost}"
remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(credentialsId: "${credentialsId}", keyFileVariable: 'kfIdentity', passphraseVariable: 'pVariable', usernameVariable: 'userName')]) {
remote.user = userName
remote.identityFile = kfIdentity
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
}
}
catch(e)
{
emailext (
subject: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' 更新失败",
body: """
详情:
FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'
状态:${env.JOB_NAME} jenkins 运行失败
URL ${env.BUILD_URL}
项目名称 ${env.JOB_NAME}
项目更新进度:${env.BUILD_NUMBER}
""",
to: "${mailto}",
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)
throw e
} //end catch
}