本文共 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/