1 Star 0 Fork 7

chilianyi/devops-maven-sample

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Jenkinsfile-argo 4.08 KB
一键复制 编辑 原始数据 按行查看 历史
stark 提交于 2023-07-19 08:30 . Modify jenkinsfile-argo
pipeline {
agent {
node {
label 'maven'
}
}
stages {
stage('checkout scm') {
parallel {
stage('checkout source') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: 'master']],
doGenerateSubmoduleConfigurations: false,
userRemoteConfigs: [[
credentialsId: "$GITHUB_CREDENTIAL_ID",
url: "https://gitee.com/chilianyi/devops-maven-sample.git"
]],
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'source'
]]
])
}
}
stage('checkout deploy') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: 'main']],
doGenerateSubmoduleConfigurations: false,
userRemoteConfigs: [[
credentialsId: "$GITHUB_CREDENTIAL_ID",
url: "https://gitee.com/chilianyi/devops-maven-deploy.git"
]],
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'deploy'
]]
])
}
}
}
}
stage('unit test') {
steps {
container('maven') {
sh 'cd source; mvn clean test'
}
}
}
stage('build & push') {
steps {
container('maven') {
sh 'cd source; mvn clean package -DskipTests'
sh 'cd source; docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER .'
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER'
}
}
}
}
stage('push latest') {
agent none
steps {
container('maven') {
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
}
}
}
stage('update mainfast') {
steps {
script {
container ('maven') {
withCredentials([usernamePassword(credentialsId: "$GITHUB_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
def encodedPassword = URLEncoder.encode("$GIT_PASSWORD",'UTF-8')
def encodedUsername = URLEncoder.encode("$GIT_USERNAME",'UTF-8')
sh """
curl -sLO https://ghproxy.com/https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.1.0/kustomize_v5.1.0_linux_amd64.tar.gz
tar xzf kustomize_v5.1.0_linux_amd64.tar.gz
cd deploy
git config --global user.email "kubesphere-cd@yunify.com"
git config --global user.name "kubesphere-cd"
git config --local credential.helper "!f() { echo username=\\$GIT_USERNAME; echo password=\\$GIT_PASSWORD; }; f"
cd deploy/dev
../../../kustomize edit set image $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest=$REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER
git add .
git commit -m "images update for dev $BUILD_NUMBER"
git push origin HEAD:main
"""
}
}
}
}
}
}
environment {
DOCKER_CREDENTIAL_ID = 'dockerhub-id'
GITHUB_CREDENTIAL_ID = 'github-id'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
REGISTRY = 'docker.io'
DOCKERHUB_NAMESPACE = 'chilianyi'
GITHUB_ACCOUNT = 'chilianyi'
APP_NAME = 'devops-java-sample'
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/chilianyi/devops-maven-sample.git
git@gitee.com:chilianyi/devops-maven-sample.git
chilianyi
devops-maven-sample
devops-maven-sample
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385