Travis CI-每个部署提供商的条件“ before_deploy”脚本

时间:2019-01-21 05:15:43

标签: deployment automation continuous-integration travis-ci travis-ci-api

我正在尝试将Travis CI部署到2个不同的提供程序(npm,firebase),我的import json data=[] def arr(): x=0 while x<1: print(x) x-=1 X.append(x) data.update(x) with open('x.txt','w')as outfile: json.dump(data,outfile) arr() print(X) 文件看起来像这样:

.travis.yml

现在,我只想在部署到Firebase(主服务器)时触发branches: only: - master - /v\d+\.\d+\.\d+/ install: - yarn before_deploy: # first provider - yarn build:storybook # second provider - yarn build:library - cp package.json lib/ - cd lib deploy: - provider: firebase ... on: branch: master - provider: npm ... on: tags: true all_branches: true 内的#first provider块。

before_deploy内部是否存在某种条件?甚至是before_deploy中的only: -branch-name

1 个答案:

答案 0 :(得分:0)

您可以将条件指定为bash脚本:

before_deploy:
  # first provider
  - |
    if [[ $TRAVIS_BRANCH != $TRAVIS_PULL_REQUEST_BRANCH && $TRAVIS_BRANCH = 'master ]]; then
      yarn build:storybook
    fi
  # second provider
  - yarn build:library
  - cp package.json lib/
  - cd lib

这是为了防止有人提出新的请求请求以使脚本运行yarn build:storybook;但是仅在travis由于推送(或任何触发构建)而由master分支构建主分支时运行。

有关更多变量,请参见此处: https://docs.travis-ci.com/user/environment-variables/#default-environment-variables