【发布时间】:2021-11-02 14:43:57
【问题描述】:
我在 Spring Boot 中制作了简单的微服务结构(三个模块),我想在更改后的微服务的 pom 中配置 gitlab ci/cd 以自动增加版本号。所以我在我的 .gitlab-ci.yml 中创建了一步:
.increment-version-module:
stage: increment version
image: ssmolinski9/docker-adoptopenjdk-11-maven-node
except:
variables:
- $GITLAB_USER_LOGIN == "login"
- $CI_COMMIT_BRANCH == "master"
before_script:
- git config --global user.email "mymail"
- git config --global push.default matching
- git config --global user.name "myname"
- git config --global user.password "$CI_INCREMENTION_PWD"
script:
- NUMBER=$(grep \<\/version $MODULE/pom.xml | head -n 1 | cut -d '>' -f2 | cut -d '<' -f1)
- NUMBER_1=$(echo $NUMBER | cut -d '.' -f1)
- NUMBER_2=$(echo $NUMBER | cut -d '.' -f2)
- NUMBER_3=$(echo $NUMBER | cut -d '.' -f3)
- NUMBER_3=$((NUMBER_3+1))
- NUMBER_new="$NUMBER_1"."$NUMBER_2"."$NUMBER_3"
- sed -i 's/\<version\>$NUMBER\<\/version\>/\<version\>$NUMBER_new\<\/version\>/g' $MODULE/pom.xml
- echo $NUMBER_new
- mvn $MAVEN_CLI_OPTS -pl $MODULE versions:set -B -DnewVersion=$NUMBER_new -f pom.xml
- mvn $MAVEN_CLI_OPTS -pl $MODULE versions:commit -B -DprocessAllModules -f pom.xml
- git commit -a -m ''$MODULE' POM Version Increment '$NUMBER_new''
- git pull https://myname:$CI_INCREMENTION_PWD@gitlab.com/url/to/my/repo/api.git HEAD:$CI_COMMIT_REF_NAME --prune --rebase
- git push https://myname:$CI_INCREMENTION_PWD@gitlab.com/url/to/my/repo/api.git HEAD:$CI_COMMIT_REF_NAME -u -f
然后我为我拥有的每个模块创建了三个工作,例如:
increment-discovery-service:
extends:
- .discovery-service
- .increment-version-module
resource_group: incrementing
虽然它可以工作,但我的管道处于 SUCCESS 状态,但是......当我拉出我的更改时,只有三个提交中的一个(最后一个)仍然存在。管道日志中的所有内容都是正确的(新版本,创建提交,推送),但我认为 git push 中的 -f 选项搞砸了。
有什么想法吗?
【问题讨论】:
-
你确定你需要 git 中的内部版本号,在工件中拥有它还不够吗?
标签: spring-boot maven gitlab microservices gitlab-ci