1 Star 0 Fork 0

littleboyzhou/jenkins-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile-kubesphere 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
littleboyzhou 提交于 2024-04-24 00:30 . 添加文件
//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: '构建模块')
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/littleboyzhou/jenkins-demo.git
git@gitee.com:littleboyzhou/jenkins-demo.git
littleboyzhou
jenkins-demo
jenkins-demo
master

搜索帮助