1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| pipeline { agent any
stages { stage('Before Build') { steps { echo "TAG: ${tag} user_name: ${user_name} repository_name: ${repository_name} git_http_url: ${git_http_url}" } } stage('Checkout Code') { steps { checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[credentialsId: '1', url: '${git_http_url}']], branches: [[name: '${full_tag}']]] } } stage('Build Container') { steps { script { load "./BuildEnv.groovy" if (!(env.credentialsId && env.registry && env.imageName)) { error "You need to set env by BuildEnv.groovy." } docker.withRegistry(env.httpRegistry, env.credentialsId) { def image = docker.build("${env.registry}${env.imageName}:${tag}") image.push() sh label: '', script: "docker rmi ${image.id}" } } } } }
post { always { echo 'finished' deleteDir() /* clean up our workspace */ }
success { emailext body: '<style class="fox_global_style">div.fox_html_content { line-height: 1.5; }ol, ul { margin-top: 0px; margin-bottom: 0px; list-style-position: inside; }div.fox_html_content { font-size: 14px; font-family: \'Microsoft YaHei UI\'; color: rgb(0, 0, 0); line-height: 1.5; }</style><div><div style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: normal;"><br></div><div style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: normal;"><br></div><ul><li><span style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: 1.5; font-size: 10.5pt; background-color: transparent;">仓库:</span><font face="Microsoft YaHei UI, Tahoma">${repository_name}</font></li><li style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: normal;"><span style="font-size: 10.5pt; line-height: 1.5; background-color: transparent;">构建状态:成功</span></li><li><span style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: 1.5; font-size: 10.5pt; background-color: transparent;">代码版本:</span><font face="Microsoft YaHei UI, Tahoma">${tag}</font></li><li><font face="Microsoft YaHei UI, Tahoma"><span style="line-height: normal;">提交用户:</span></font><font face="monospace, monospace"><span style="line-height: normal;">${user_name}</span></font></li><li><font face="Microsoft YaHei UI, Tahoma"><span style="line-height: normal;">仓库地址: <a href="${repository_git_http_url}/commit/${checkout_sha}">${repository_git_http_url}</a></span></font></li></ul></div>', subject: '【构建通知】仓库:${repository_name} TAG: ${tag}', to: "${env.notifyUsers}" }
failure { emailext attachLog: true, body: '<style class="fox_global_style">div.fox_html_content { line-height: 1.5; }ol, ul { margin-top: 0px; margin-bottom: 0px; list-style-position: inside; }div.fox_html_content { font-size: 14px; font-family: \'Microsoft YaHei UI\'; color: rgb(0, 0, 0); line-height: 1.5; }</style><div><div style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: normal;"><br></div><div style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: normal;"><br></div><ul><li><span style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: 1.5; font-size: 10.5pt; background-color: transparent;">仓库:</span><font face="Microsoft YaHei UI, Tahoma">${repository_name}</font></li><li style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: normal;"><span style="font-size: 10.5pt; line-height: 1.5; background-color: transparent;">构建状态:失败</span></li><li><span style="font-family: \'Microsoft YaHei UI\', Tahoma; line-height: 1.5; font-size: 10.5pt; background-color: transparent;">代码版本:</span><font face="Microsoft YaHei UI, Tahoma">${tag}</font></li><li><font face="Microsoft YaHei UI, Tahoma"><span style="line-height: normal;">提交用户:</span></font><font face="monospace, monospace"><span style="line-height: normal;">${user_name}</span></font></li></ul></div>', subject: '【构建通知】仓库:${repository_name} TAG: ${tag}', to: "${env.notifyUsers}" } } }
|