提交jenkins构建脚本

This commit is contained in:
zhouxiunai
2018-12-03 10:53:37 +08:00
parent 021de12235
commit fa2d15bb56
3 changed files with 98 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
FROM frolvlad/alpine-oraclejdk8:slim
MAINTAINER xiunai78 <154707516@qq.com>
# Add the service itself
ARG JAR_FILE
ADD ${JAR_FILE} /usr/local/msgexchangeapi/myapp.jar
EXPOSE 8080
ENTRYPOINT ["/usr/bin/java", "-jar", "/usr/local/msgexchangeapi/myapp.jar"]
+68
View File
@@ -0,0 +1,68 @@
node {
def mailto="154707516@qq.com" //邮件接收人员列表
def containerName="msgexchangeapi" //容器名称
def imageVersion="0.0.1-SNAPSHOT"
def imageName="130.120.3.193/com.gzzn.omms/msgexchangeapi:${imageVersion}" //镜像名称
def credentialsId="e41b57a4-436a-4617-817c-9e3f25a8a47f" //ssh证书id
def deployHost="130.120.3.231" //发布到的主机
def export=95 //暴露端口
try
{
checkout scm
docker.image('maven:3-alpine').inside('-v /root/.m2:/root/.m2') {
stage('build'){
sh 'mvn clean package dockerfile:build dockerfile:push -Dmaven.test.skip=true'
}
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 ${export}:8080 --name ${containerName} ${imageName}",sudo: true
}
}
} //end docker
//发送成功邮件
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']]
)
}
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
}
+20
View File
@@ -100,6 +100,26 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.4</version>
<configuration>
<username>gzzn</username>
<password>Gzzn@2018</password>
<!-- 镜像tag -->
<tag>${project.version}</tag>
<!--useMavenSettingsForAuth>true</useMavenSettingsForAuth -->
<!-- 禁止使用谷歌商店认证 -->
<googleContainerRegistryEnabled>false</googleContainerRegistryEnabled>
<repository>130.120.3.193/${project.groupId}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>