代码拉取完成,页面将自动刷新
pipeline {
agent {
node {
label 'maven'
}
}
stages {
stage('拉取代码') {
agent none
steps {
container('maven') {
git(url: 'https://gitee.com/xmlvhy/java-devops-demo.git', credentialsId: 'gitee', branch: 'master', changelog: true, poll: false)
sh 'pwd && ls -alh'
}
}
}
stage('单元测试') {
agent none
steps {
container('maven') {
sh 'mvn clean package -Dmaven.test.skip=true'
sh 'pwd && ls -alh'
}
}
}
stage('镜像构建') {
agent none
steps {
container('maven') {
sh 'ls -alh'
sh '''docker build -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER .
'''
}
}
}
stage('推送镜像') {
agent none
steps {
container('maven') {
withCredentials([usernamePassword(credentialsId: 'aliyun-harbor', passwordVariable: 'DOCKER_PWD_VAR', usernameVariable: 'DOCKER_USER_VAR',)]) {
sh 'echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin'
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER'
}
}
}
}
stage('部署到dev环境') {
agent none
steps {
container('maven') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
variable: 'KUBECONFIG')
]) {
sh 'envsubst < deploy/deploy_codesofun.yaml | kubectl apply -f -'
}
}
}
}
}
environment {
DOCKER_CREDENTIAL_ID = 'dockerhub-id'
GITHUB_CREDENTIAL_ID = 'github-id'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
DOCKERHUB_NAMESPACE = 'codesofun'
GITHUB_ACCOUNT = '1059224309@qq.com'
APP_NAME = 'java-devops-demo'
}
parameters {
string(name: 'TAG_NAME', defaultValue: '', description: '')
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。