Jenkins 共享库2(实战K8S篇)
docker编译使用的groovy脚本package org.devopsdef docker_bui() {withCredentials([usernamePassword(credentialsId: 'dockeropa', passwordVariable: 'Password', usernameVariable: 'Username')]) {sh '''docker login -
·
package org.devops
def docker_bui() {
withCredentials([usernamePassword(credentialsId: 'dockeropa', passwordVariable: 'Password', usernameVariable: 'Username')]) {
sh '''
docker login -u$Username -p$Password kk.jsj.com
docker build -t ${name}:${BUILD_ID} .
docker tag ${name}:${BUILD_ID} ${image}
docker push ${image}
echo ${image}
docker rmi ${image}
docker rmi ${name}:${BUILD_ID}
echo ${name}:${BUILD_ID}
'''
}
}
package org.devops
def test_kue() {
withKubeConfig([credentialsId:'kj8s',namespace:'default']) {
sh ' echo "10.0" >> /etc/hosts'
sh "sed -i 's#{{image}}#${image}#g' k8s.yaml"
sh 'kubectl apply -f k8s.yaml'
}
}
@Library ("jr-shared-library") _
def docker_test_bui = new org.devops.docker_test_bui()
def deploy_test = new org.devops.deploy_test()
pipeline {
environment {
name="portal"
image="JSS.com/libary/jr-prod-01:${name}$BUILD_ID"
}
agent {
kubernetes {
inheritFrom 'maven-test'
}
}
options{
timestamps ()
disableConcurrentBuilds ()
buildDiscarder(logRotator(numToKeepStr: '10'))
}
stages {
stage('Get Code') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/sit']], extensions: [], userRemoteConfigs: [[credentialsId: 'vip', url: 'https://gitHUB.OOOX.com/youhuomenhu/backend.git']]])
}
}
stage('Java-build') {
steps {
container('maven36'){
sh 'mvn clean package'
}
}
}
stage('Docker-build') {
steps {
container('docker'){
script {
docker_test_bui.docker_bui()
}
}
}
}
stage('Deploy....') {
steps {
container('kubectl'){
script {
deploy_test.test_kue()
}
}
}
}
}
//消息推送
post {
always {
pushplus ("001")
}
}
}
更多推荐
已为社区贡献82条内容
所有评论(0)