1 Star 0 Fork 7

smjg/devops-maven-sample

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Jenkinsfile 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
shichunshan 提交于 2023-08-24 16:00 . 修改jenkins配置
pipeline {
agent {
node {
label 'maven'
}
}
parameters {
string(name:'REGISTRY',defaultValue: 'harbor.internal.virtueit.net',description:'镜像仓库地址')
string(name:'DOCKERHUB_NAMESPACE',defaultValue: 'devops',description:'')
string(name:'APP_NAME',defaultValue: 'devops-sample',description:'')
}
environment {
DOCKER_CREDENTIAL_ID = 'harbor'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
DOCKERHUB_NAMESPACE = 'devops'
APP_NAME = 'devops-java-sample'
}
stages {
stage('Checkout SCM') {
agent none
steps {
git(url: 'https://gitee.com/smjg_001/devops-maven-sample.git', credentialsId: 'gitlab', changelog: true, poll: false)
}
}
// stage('Unit Test') {
// agent none
// steps {
// container('maven') {
// sh '''mvn clean -gs `pwd`/configuration/settings.xml test
// '''
// }
// }
// }
stage('Build and Push') {
agent none
steps {
container('maven') {
sh '''mvn -Dmaven.test.skip=true clean package
'''
sh '''docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER .
'''
withCredentials([usernamePassword(credentialsId : 'harbor' ,passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,)]) {
sh '''echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin
'''
sh '''docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER
'''
}
}
}
}
stage('Artifacts') {
agent none
steps {
archiveArtifacts 'target/*.jar'
}
}
stage('Deploy to Dev') {
agent none
steps {
// input(message: '@admin ', submitter: 'admin')
container('maven') {
withCredentials([kubeconfigContent(credentialsId : 'kubeconfig' ,variable : 'KUBECONFIG_CONTENT' ,)]) {
sh '''mkdir ~/.kube
echo "$KUBECONFIG_CONTENT" > ~/.kube/config
envsubst < deploy/dev/deployment.yaml | kubectl apply -f -
envsubst < deploy/dev/service.yaml | kubectl apply -f -
'''
}
}
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/smjg_001/devops-maven-sample.git
[email protected]:smjg_001/devops-maven-sample.git
smjg_001
devops-maven-sample
devops-maven-sample
master

搜索帮助