我正在尝试使用Travis CI构建将自动化版本部署配置为Github版本。我的.travis.yml
文件看起来像:
language: java
jdk: oraclejdk8
branches:
only:
- master
before_install: mvn package -DskipTests=true -DbuildNumber=$TRAVIS_BUILD_NUMBER
before_deploy:
- git config --local user.name "$USER_NAME"
- git config --local user.email "$USER_EMAIL"
- export GIT_TAG=1.0.$TRAVIS_BUILD_NUMBER
- git tag $GIT_TAG -a -m "Generated tag from TravisCI build $TRAVIS_BUILD_NUMBER"
- git push origin $GIT_TAG
deploy:
provider: releases
api_key: $GITHUB_TOKEN
file:
- target/tweetsched-dto-1.0.$TRAVIS_BUILD_NUMBER.jar
name: tweetsched-dto-1.0.$TRAVIS_BUILD_NUMBER
skip-cleanup: true
on:
tags: true
repo: Tweetsched/tweetsched-dto
branches:
only:
- master
notifications:
email:
on_success: never
on_failure: always
我想要的-PR合并到Master分支Travis CI,在before_deploy
步骤中创建一个新标签,然后根据该标签创建新版本。但是当我对其进行测试时,我总是会在Travis CI日志中收到一条消息:
跳过发布提供程序的部署,因为这不是一个 标记的提交
没有任何关于为什么不创建标签的消息。我究竟做错了什么?以及如何正确配置Travis以从Master分支成功构建后发布新版本的工件?
答案 0 :(得分:2)
最后,我已经解决了该问题,最终的config版本如下:
language: java
jdk: oraclejdk8
branches:
only:
- master
before_install: mvn package -DskipTests=true -DbuildNumber=$TRAVIS_BUILD_NUMBER
before_deploy:
- export TRAVIS_TAG="1.0.$TRAVIS_BUILD_NUMBER"
- echo "$TRAVIS_TAG" "$TRAVIS_COMMIT"
- git config --local user.name "$USER_NAME"
- git config --local user.email "$USER_EMAIL"
- git tag "$TRAVIS_TAG" "$TRAVIS_COMMIT"
deploy:
provider: releases
tag_name: $TRAVIS_TAG
target_commitish: $TRAVIS_COMMIT
name: $TRAVIS_TAG
overwrite: true
skip_cleanup: true
api_key: $GITHUB_TOKEN
file_glob: true
file:
- target/tweetsched-dto-1.0.$TRAVIS_BUILD_NUMBER.jar
on:
branch: master
repo: Tweetsched/tweetsched-dto
notifications:
email:
on_success: never
on_failure: always
答案 1 :(得分:1)
为了让Travis考虑标记,您需要设置$TRAVIS_TAG
env var。参见https://docs.travis-ci.com/user/deployment/#conditional-releases-with-on
export TRAVIS_TAG=$GIT_TAG