TravisCI: Run after_success on a specific branch

给你一囗甜甜゛ 提交于 2019-12-04 16:45:11

问题


I would like to know how to run an after_success script only for a specific branch.

I am using a custom script to deploy the app after build passes. I would only like to run this when on prod branch.

So far, I have tried the following:

#1

after_success:
  - # some deployment script
  on: prod

#2

branches:
  only:
    - prod
    after_success:
      - # some deployment script
#3

after_success:
  branches:
    only:
      - prod
  - # some deployment script

Any suggestions?


回答1:


I solved it by writing a simple script using TRAVIS_BRANCH environment variable and executed the script in after_success

.travis.yml

after_success:
- ./deploy.sh

deploy.sh

#!/bin/bash
if [ "$TRAVIS_BRANCH" == "prod" ]; then
  // do the deploy
fi



回答2:


You can also do this by using the script provider in the deploy phase of your build. This approach is a bit cleaner but only allows one command, unlike after_success.

deploy:
  provider: script
  script: # some deployment script
  on:
    branch: prod


来源:https://stackoverflow.com/questions/31338562/travisci-run-after-success-on-a-specific-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!