代码拉取完成,页面将自动刷新
//kubesphere 版本的部署文件
pipeline {
agent {
node {
label 'maven'
}
}
stages {
stage('拉取代码') {
steps {
git(url: 'https://gitee.com/littleboyzhou/jenkins-demo.git', credentialsId: 'gitee', branch: 'master', changelog: true, poll: false)
sh 'echo 正在构建 $PROJECT_NAME 版本号:$PROJECT_VERSION 将会提交给 $REGISTRY 镜像仓库'
}
}
stage('构建镜像-推送镜像') {
agent none
steps {
container('maven') {
sh 'mvn -Dmaven.test.skip=true clean package'
sh 'docker build -f Dockerfile -t $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
withCredentials([usernamePassword(credentialsId: 'aliyun-docker-id', passwordVariable: 'DOCKER_PASSWORD', usernameVariable: 'DOCKER_USERNAME')]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:latest '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:latest '
}
}
}
}
stage('部署到k8s') {
agent none
steps {
container('maven') {
withCredentials([kubeconfigFile(credentialsId: 'demo-kubeconfig', variable: 'KUBECONFIG')]) {
sh 'kubectl apply -f jenkins-demo-k8s.yaml'
}
}
}
}
}
environment {
DOCKER_CREDENTIAL_ID = 'aliyun-docker-id'
REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
DOCKERHUB_NAMESPACE = 'devops-pipeline-jenkins'
BRANCH_NAME = 'master'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
}
parameters {
string(name: 'PROJECT_VERSION', defaultValue: '', description: '项目版本')
string(name: 'PROJECT_NAME', defaultValue: '', description: '构建模块')
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。