加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Jenkinsfile-online-1 3.55 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2023-05-12 19:20 . u
pipeline {
agent {
node {
label 'maven'
}
}
parameters {
string(name:'TAG_NAME',defaultValue: '',description:'')
}
environment {
ALIYUN_DOCKER_CREDENTIAL_ID = 'aliyun-dockerhub-id'
ALIYUN_REGISTRY = 'registry.cn-beijing.aliyuncs.com'
ALIYUN_DOCKERHUB_NAMESPACE = 'wx001'
DOCKER_CREDENTIAL_ID = "$ALIYUN_DOCKER_CREDENTIAL_ID"
REGISTRY = "$ALIYUN_REGISTRY"
DOCKERHUB_NAMESPACE = "$ALIYUN_DOCKERHUB_NAMESPACE"
GITHUB_CREDENTIAL_ID = 'github-id'
GITHUB_ACCOUNT = 'idwxing'
GITEE_CREDENTIAL_ID = 'gitee-id'
GITEE_ACCOUNT = 'idwxing'
APP_NAME = 'devops-java-sample'
}
stages {
stage ('checkout scm') {
steps {
checkout(scm)
}
}
stage ('unit test') {
steps {
container ('maven') {
sh 'mvn clean -gs `pwd`/configuration/settings.xml test'
}
}
}
stage ('build & push') {
steps {
container ('maven') {
sh 'mvn -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$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-$BRANCH_NAME-$BUILD_NUMBER'
}
}
}
}
stage('argocd') {
steps {
container('maven') {
sh 'git config --global user.email "kubesphere@yunify.com" '
sh 'git config --global user.name "kubesphere" '
withCredentials([usernamePassword(credentialsId: "$GITEE_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh 'echo 123 >> 1.txt'
sh 'git add .'
sh 'git commit -m SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
sh 'git remote -v'
sh 'git push https://$GIT_USERNAME:$GIT_PASSWORD@gitee.com/$GITEE_ACCOUNT/devops-java-sample.git'
}
}
}
}
stage('push with tag'){
when{
expression{
return params.TAG_NAME =~ /v.*/
}
}
steps {
container ('maven') {
input(id: 'release-image-with-tag', message: 'release image with tag?')
withCredentials([usernamePassword(credentialsId: "$GITEE_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh 'git config --global user.email "kubesphere@yunify.com" '
sh 'git config --global user.name "kubesphere" '
sh 'git tag -a $TAG_NAME -m "$TAG_NAME" '
sh 'git remote -v'
sh 'git push https://$GIT_USERNAME:$GIT_PASSWORD@gitee.com/$GITEE_ACCOUNT/devops-java-sample.git --tags --ipv4'
}
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
}
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化