博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jenkins流水线脚本 从sonar代码扫描,到maven构建,到docker打包,到k8s发布
阅读量:4073 次
发布时间:2019-05-25

本文共 2429 字,大约阅读时间需要 8 分钟。

 

podTemplate(label: 'jnlp-slave', cloud: 'kubernetes',containers: [containerTemplate(name: 'jnlp',image: "cnych/jenkins:jnlp6",),containerTemplate(name: 'maven',image: "maven:3-openjdk-8",ttyEnabled: true,command: 'cat',), containerTemplate(name: 'docker',image: "docker:stable",ttyEnabled: true,command: 'cat',), ],  volumes: [hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),nfsVolume(mountPath: '/home/jenkins/agent', serverAddress:'192.168.4.101' , serverPath: '/data01/nfs/amp/agent'),], ){  node('jnlp-slave') { echo 'pullCode'stage('代码') {echo '拉取代码'checkout([$class:'GitSCM',branches:[[name:'']],userRemoteConfigs:[[credentialsId:'',url:'https://github.com/shuaizai88/test_junit']]])script {build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()}}echo 'step end'stage('代码检查和单元测试'){ echo '55e98da79390456689c382ed8d111111'echo 'step end'echo '55e98da79390456689c382ed8d111112'container('maven') {sh ''' mvn org.jacoco:jacoco-maven-plugin:prepare-agent -f pom.xml clean test -Dautoconfig.skip=true -Dmaven.test.skip=false -Dmaven.test.failure.ignore=true -settings ./server.xml ''' junit '**/target/surefire-reports/*.xml'} echo 'step end'} stage('构建'){ echo '55e98da79390456689c382ed8d111113'container('maven') {sh ''' mvn clean package -Dmaven.test.skip=true -settings ./server.xml ''' } echo 'step end'echo '55e98da79390456689c382ed8d111114'container('docker') {def hubImgName = "test:lastest"                               withCredentials([usernamePassword(credentialsId: 'b953abf9-193c-41c6-8c0d-bad419f1136d', passwordVariable: 'password', usernameVariable: 'username')]) {                    sh "docker login -u ${username} -p ${password} docker私服url"                        sh "docker build -t ${hubImgName} ."                    sh "docker push ${hubImgName}"                    sh "docker rmi -f ${hubImgName}"                               }} echo 'step end'} stage('发布'){ echo '55e98da79390456689c382ed8d111115'timeout(20) {input (message:"是否发布?")}echo 'step end'echo '55e98da79390456689c382ed8d111116'withCredentials([string(credentialsId: '007c2a04-79c7-4baf-be4f-2b613aba9ad0', variable: 'yaml')]) {                sh 'echo "${yaml}" | base64 -d > deploy.yaml'            }                        withKubeConfig([credentialsId: '7b2678b4-75c0-48c2-9d34-b847b98c689c']) {              sh "kubectl apply -f deploy.yaml"            }echo 'step end'} }}

 

 

 

转载地址:http://thwni.baihongyu.com/

你可能感兴趣的文章
支付宝生活号服务号 用户信息获取 oauth2 登录对接 springboot java
查看>>
CodeForces #196(Div. 2) 337D Book of Evil (树形dp)
查看>>
uva 12260 - Free Goodies (dp,贪心 | 好题)
查看>>
uva-1427 Parade (单调队列优化dp)
查看>>
【设计模式】学习笔记14:状态模式(State)
查看>>
poj 1976 A Mini Locomotive (dp 二维01背包)
查看>>
斯坦福大学机器学习——因子分析(Factor analysis)
查看>>
项目导入时报错:The import javax.servlet.http.HttpServletRequest cannot be resolved
查看>>
linux对于没有写权限的文件如何保存退出vim
查看>>
Windows下安装ElasticSearch6.3.1以及ElasticSearch6.3.1的Head插件
查看>>
IntelliJ IDEA 下的svn配置及使用的非常详细的图文总结
查看>>
【IntelliJ IDEA】idea导入项目只显示项目中的文件,不显示项目结构
查看>>
ssh 如何方便的切换到其他节点??
查看>>
JSP中文乱码总结
查看>>
Java-IO-File类
查看>>
Java-IO-java的IO流
查看>>
Java-IO-输入/输出流体系
查看>>
Java实现DES加密解密
查看>>
HTML基础
查看>>
Java IO
查看>>