代码拉取完成,页面将自动刷新
pipeline {
agent {
node {
label 'haimaxy-jnlp'
}
}
stages {
stage('Init') {
steps{
script{
println "welcome to Nick learn"
println env.WORKSPACE
module_test = load env.WORKSPACE + "/groovy/jenkins-module.groovy"
sh 'mkdir workplace'
}
}
}
stage('Git Source') {
steps{
script{
dir("${env.WORKSPACE}/workplace"){
println "welcome to git Source"
//git branch: 'env/dev', credentialsId: '11111',url: 'git@192.168.108.132:root/jenkins_slave_k8s.git'
git 'https://gitee.com/clin/pipeline-demo'
}
}
}
}
stage('Maven Build') {
steps {
script {
container('maven') {
dir("${env.WORKSPACE}/workplace"){
sh 'mvn clean package'
//sh 'mvn -v'
}
}
}
}
}
stage('Docker Build') {
steps {
script {
container('docker') {
sh 'docker login -u ' + HARBOR_CREDS_USR + ' -p ' + HARBOR_CREDS_PSW + ' ' + HARBOR_HOST
sh "docker build --build-arg JAR_FILE=`ls workplace/target/*.jar |cut -d '/' -f2` -t " + HARBOR_HOST + "/" + DOCKER_IMAGE + ":" + GIT_TAG + " --no-cache ."
sh "docker push " + HARBOR_HOST + "/" + DOCKER_IMAGE + ":" + GIT_TAG
sh "docker rmi " + HARBOR_HOST + "/" + DOCKER_IMAGE + ":" + GIT_TAG
}
}
}
}
stage('K8s Deploy') {
steps {
script {
container('kubectl') {
sh "sed -e 's#{IMAGE_URL}#" + HARBOR_HOST + "/" + DOCKER_IMAGE + "#g;s#{IMAGE_TAG}#" + GIT_TAG + "#g;s#{APP_NAME}#" + APP_NAME + "#g;s#{SPRING_PROFILE}#k8s-test#g' k8s-deployment.tpl > k8s-deployment.yml"
sh "sed -e 's#{APP_NAME}#" + APP_NAME + "#g;s#{NODE_PORT}#" + NODE_PORT + "#g' k8s-deployment-svc.tpl > k8s-deployment-svc.yml"
try{
sh "cat k8s-deployment.yml"
sh "cat k8s-deployment-svc.yml"
}catch (Exception e) {
println e
}
try{
sh "kubectl delete rc " + APP_NAME + " --namespace=" + K8S_NAMESPACE
}catch (Exception e) {
println e
}
try{
sh "kubectl delete svc " + APP_NAME + " --namespace=" + K8S_NAMESPACE
}catch (Exception e) {
println e
}
sh "kubectl apply -f k8s-deployment.yml --namespace=" + K8S_NAMESPACE
sh "kubectl apply -f k8s-deployment-svc.yml --namespace=" + K8S_NAMESPACE
}
}
}
}
stage('API Test') {
steps {
script {
container('newman') {
dir("${env.WORKSPACE}/workplace"){
try{
sleep 5
//sh 'newman run postman/jenkins_demo_test.postman_collection.json'
}catch (Exception e) {
println e
}
}
}
}
}
}
}
post{
failure {
script {
module_test.send_email_results("Failed","Master","chenlin@htffund.com")
}
}
success {
script {
module_test.send_email_results("Success","Master","chenlin@htffund.com")
}
}
}
environment {
HARBOR_CREDS = credentials('jenkins-harbor-creds')
// K8S_CONFIG = credentials('jenkins-k8s-config')
GIT_TAG = sh(returnStdout: true,script: 'echo ' + BUILD_NUMBER ).trim()
}
parameters {
//string(name: 'HARBOR_HOST', defaultValue: '192.168.108.131', description: 'harbor仓库地址')
//string(name: 'DOCKER_IMAGE', defaultValue: 'library/jenkins_demo', description: 'docker镜像名')
string(name: 'HARBOR_HOST', defaultValue: 'registry.cn-shanghai.aliyuncs.com', description: 'harbor仓库地址')
string(name: 'DOCKER_IMAGE', defaultValue: 'wpower/wpower.com2', description: 'docker镜像名')
string(name: 'APP_NAME', defaultValue: 'jenkinsdemo', description: 'k8s中标签名')
string(name: 'NODE_PORT', defaultValue: '30000', description: 'Service端口')
string(name: 'K8S_NAMESPACE', defaultValue: 'devops', description: 'k8s的namespace名称')
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。