text Jenkins管道支持k8 / docker
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Jenkins管道支持k8 / docker相关的知识,希望对你有一定的参考价值。
pipeline {
agent any
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '1'))
}
parameters {
choice(name: 'ENVIRONMENT', choices: "Production", description: 'Select target environment')
booleanParam(defaultValue: true, name: 'PROVISION', description: 'Provision Kubernetes Infrastructure')
string(name: 'CLUSTER_NAME', defaultValue: 'your-cluster-na', description: 'GKE Cluster Name')
string(name: 'CLUSTER_ZONE', defaultValue: 'us-central1-a', description: 'GKE Cluster Zone')
string(name: 'PROJECT', defaultValue: 'asdfasdfasdf', description: 'Google Cloud Project Name')
string(name: 'REPOSITORY_NAME', defaultValue: 'asdfasdfasdf-v1', description: 'Google Cloud Repository Name')
}
environment {
IMAGE_TAG = "${env.GIT_COMMIT}"
}
stages {
stage('Notify Slack') {
steps {
slackSend (token: 'ek3r55KGGtmfs5edI1TdktG0', baseUrl: 'https://hooks.slack.com/services/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', channel: '#development', color: '#0000FF', message: "BUILD STARTED: For 'blitzalytics-v1', Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
}
stage('Setup gcloud cli') {
steps {
sh "gcloud container clusters get-credentials ${params.CLUSTER_NAME} --project=${params.PROJECT} --zone=${params.CLUSTER_ZONE}"
sh "echo Y | gcloud auth configure-docker"
}
}
stage('Checkout source code from gcloud') {
steps {
sh "gcloud source repos clone ${params.REPOSITORY_NAME} --project=${params.PROJECT}"
sh "ls -la"
sh "cd ${params.REPOSITORY_NAME}"
sh "ls -la"
}
}
stage('Build Docker Image') {
steps {
dir("${params.REPOSITORY_NAME}") {
echo "*** Building docker image with IMAGE_TAG: ${IMAGE_TAG}"
sh "pwd"
sh "ls -la"
sh "docker build -t gcr.io/${params.PROJECT}/${params.REPOSITORY_NAME}:${IMAGE_TAG} ."
sh "docker push gcr.io/${params.PROJECT}/${params.REPOSITORY_NAME}:${IMAGE_TAG}"
}
}
}
stage('Update Deployment(s)') {
steps {
sh "kubectl set image deployment/${params.REPOSITORY_NAME} *=gcr.io/${params.PROJECT}/${params.REPOSITORY_NAME}:${IMAGE_TAG}"
}
}
}
post {
always {
cleanWs()
}
}
}
以上是关于text Jenkins管道支持k8 / docker的主要内容,如果未能解决你的问题,请参考以下文章
Jenkins groovy 管道 - 为另一个管道调用构建步骤
如何在没有 Maven 和 Docker 的 Jenkins 声明式管道中执行 SonarQube 扫描仪
Mac部署k8s
Jenkins管道将Node + Gulp项目中产生的战争发布给Artifactory
Jenkins+K8s实现持续集成 网盘分享 百度云
2.使用jenkins自动构建并发布应用到k8s集群