文章目录
- 1. 参数化构建过程
-
- git凭证
- git全局参数
- 2.构建触发器
- 3. 高级选项
- 4. 通过 Pipeline Script 脚本
1. 参数化构建过程
git凭证
git全局参数
在这边配置git参数,以后构建时候使用
2.构建触发器
由于本项目手动触发,这边不设置。
3. 高级选项
略
4. 通过 Pipeline Script 脚本
pipeline {
agent anytools {
jdk 'jdk8'}parameters {
gitParameter defaultValue: 'master', name: 'branch', type: 'PT_BRANCH', sortMode: 'DESCENDING_SMART', description: 'Please select your branch'gitParameter defaultValue: 'latest', name: 'tag', type: 'PT_TAG', sortMode: 'DESCENDING_SMART'}stages {
stage('Maven Build') {
steps {
// Get some code from a GitHub repositoryecho "branch: ${params.branch}"echo "tag: ${params.tag}"cleanWs() checkout([$class: 'GitSCM', branches: [[name: "${params.branch}"]],userRemoteConfigs: [[credentialsId: '****', url: '*****']]])withMaven(maven: 'maven 3.8.4'){
sh 'mvn -U -Dmaven.test.skip=true clean package'} }}stage('Docker Build') {
steps {
script {
imageTag = "${params.tag}"env.BUILD_VERSION = imageTagenv.IMAGE_NAME = 'demo'echo "env.BUILD_VERSION: ${env.BUILD_VERSION}"echo "env.DOCKER_HUB: ${env.DOCKER_HUB}"}sh "docker rmi -f ${env.DOCKER_HUB}/${env.IMAGE_NAME}"sh "docker build -t ${env.DOCKER_HUB}/${env.IMAGE_NAME}:${env.BUILD_VERSION} --build-arg \"BASE_DOCKER_JAVA=openjdk:8\" --progress=plain --no-cache ."sh "docker push ${env.DOCKER_HUB}/${env.IMAGE_NAME}:${env.BUILD_VERSION}"}}stage('Deploy K8S') {
steps {
script {
imageTag = "${params.tag}"env.BUILD_VERSION = imageTagenv.IMAGE_NAME = 'demo'}sh "sed \"s#{
{docker-image}}#${env.DOCKER_HUB}/${env.IMAGE_NAME}:${env.BUILD_VERSION}#g\" < k8s.yaml > deploy.yaml"sh "cat deploy.yaml"sh 'kubectl apply -f deploy.yaml --namespace=test-dev'}}}
}