Bintray 部署

此页面记录了使用 dpl v1 进行部署,目前它是默认版本。下一个主要版本 dpl v2 将很快发布,我们建议您开始使用它。请参阅 我们的博文 获取详细信息。dpl v2 文档可在此处找到

Travis CI 可以自动将您的构建工件部署到 Bintray

这是一个示例 .travis.yml

deploy:
  provider: bintray
  file: "Path to a descriptor file, containing information for the Bintray upload"
  user: "Bintray user"
  key: "Bintray API key"
  passphrase: "Optional. In case a passphrase is configured on Bintray and GPG signing is used"
  skip_cleanup: true # to upload artifacts created during the build

加密您的 API 密钥 #

建议您加密您的 API 密钥。您可以使用 travis 命令行客户端和以下命令加密此密钥

$ travis encrypt <YOUR BINTRAY API KEY> --add deploy.key

示例

$ travis encrypt ab012cd345678901234e456fa7bc89def01a23b4 --add deploy.key

要从中部署的分支 #

默认情况下,Travis CI 仅从您的 **master** 分支进行部署。

您可以使用 **on** 选项显式指定要从中部署的分支

deploy:
  ..
  on: production

或者,您还可以将其配置为从所有分支部署。

deploy:
  ..
  on:
    all_branches: true

从 Pull Request 触发的构建永远不会触发部署。

条件部署 #

只有在满足某些条件时才能部署。请参阅 使用 on: 进行条件发布

在部署前后运行命令 #

有时您希望在部署之前或之后运行命令。为此,您可以使用 before_deployafter_deploy 阶段。只有在 Travis CI 实际进行部署时才会触发这些阶段。

before_deploy: "echo 'ready?'"
deploy:
  ..
after_deploy:
  - ./after_deploy_1.sh
  - ./after_deploy_2.sh

dry_run 选项 #

为了测试部署配置,您可以添加 dry_run: true 以防止连接到 Bintray 服务器

deploy:
  ..
  dry_run: true

描述符文件示例 #

描述符采用 JSON 文件格式,分为三个部分

{
    "package": {
        "name": "auto-upload",
        "repo": "myRepo",
        "subject": "myBintrayUser",
        "desc": "I was pushed completely automatically",
        "website_url": "www.jfrog.com",
        "issue_tracker_url": "https://github.com/bintray/bintray-client-java/issues",
        "vcs_url": "https://github.com/bintray/bintray-client-java.git",
        "github_use_tag_release_notes": true,
        "github_release_notes_file": "RELEASE.txt",
        "licenses": ["MIT"],
        "labels": ["cool", "awesome", "gorilla"],
        "public_download_numbers": false,
        "public_stats": false,
        "attributes": [{"name": "att1", "values" : ["val1"], "type": "string"},
                       {"name": "att2", "values" : [1, 2.2, 4], "type": "number"},
                       {"name": "att5", "values" : ["2014-12-28T19:43:37+0100"], "type": "date"}]
    },

    "version": {
        "name": "0.5",
        "desc": "This is a version",
        "released": "2015-01-04",
        "vcs_tag": "0.5",
        "attributes": [{"name": "VerAtt1", "values" : ["VerVal1"], "type": "string"},
                       {"name": "VerAtt2", "values" : [1, 3.3, 5], "type": "number"},
                       {"name": "VerAtt3", "values" : ["2015-01-01T19:43:37+0100"], "type": "date"}],
        "gpgSign": false
    },

    "files":
        [
        {"includePattern": "build/bin(.*)*/(.*\\.gem)", "excludePattern": ".*/do-not-deploy/.*", "uploadPattern": "gems/$2"},
        {"includePattern": "build/docs/(.*)", "uploadPattern": "docs/$1"}
        ],
    "publish": true
}

包部分 #

Bintray 包信息。以下信息在开源项目中是强制性的

  • name 是 Bintray 包名称
  • repo 是 Bintray 存储库名称
  • subject 是 Bintray 主题,可以是用户或组织
  • vcs_url 是 Bintray 版本控制系统 URL,例如 GitHub 存储库 URL
  • licensesBintray 许可证,它是一个至少包含一项的列表。

版本部分 #

包版本信息。如果版本已存在于 Bintray 上,则只有 name 字段是强制性的。

文件部分 #

配置您要上传到 Bintray 的文件及其上传路径。

您可以定义一个或多个模式组。每个组包含三个模式

  • includePattern:采用 Ruby 正则表达式形式的模式,指示要上传到 Bintray 的文件路径。如果文件位于根目录中,则必须指示相对路径:\./
  • excludePattern:可选。采用 Ruby 正则表达式形式的模式,指示要从 includePattern 指定的文件列表中删除的文件路径。
  • uploadPattern:Bintray 上的上传路径。路径可以包含 $1、$2 等形式的符号,这些符号将替换为 include 模式中定义的捕获组。

在上面的示例中,上传以下文件

  • 位于 build/bin/(包括子目录)下的所有 gem 文件,但不包括 do-not-deploy 目录下的文件。这些文件将上传到 Bintray 的 gems 文件夹下。
  • build/docs 下的所有文件。这些文件将上传到 Bintray 的 docs 文件夹下。

**注意:**作为 includePatternexcludePattern 属性一部分定义的正则表达式必须用括号括起来。

Debian 上传 #

当使用自动索引布局将工件上传到 Bintray 上的 Debian 存储库时,需要 Debian 发行版信息,并且必须指定。此信息在描述符文件中由 matrixParams 指定,作为文件闭包的一部分,如下例所示

uploadPattern 应符合 bintray 自动布局方案

"files":
    [{"includePattern": "build/bin/(.*\.deb)", "uploadPattern": "pool/main/m/mypackage/$1",
    "matrixParams": {
        "deb_distribution": "vivid",
        "deb_component": "main",
        "deb_architecture": "amd64"}
    }
]

覆盖现有文件 #

如果给定名称的工件已存在于 Bintray 存储库中,则默认情况下不会覆盖它。如果要替换现有文件,请在矩阵属性中定义 override 密钥

"files":
    [{"includePattern": "build/bin/(myfile.bin)", "uploadPattern": "$1",
    "matrixParams": {
        "override": 1 }
    }
]