git Bitbucket Pipelines - 具有相同步骤的多个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42304478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bitbucket Pipelines - multiple branches with same steps
提问by Gery Teague
Is it possible to combine multiple branches that have the same steps within bitbucket pipelines?
是否可以在 bitbucket 管道中组合具有相同步骤的多个分支?
ex: The teams I work on use one of two names for their review branches, either "rev" or "staging". Either way the same steps are used to publish to our review server. Right now the branches are called out separately.
例如:我工作的团队使用两个名称之一作为他们的分支,“rev”或“staging”。无论哪种方式,都使用相同的步骤发布到我们的评论服务器。现在分支被分别调用。
pipelines:
branches:
rev:
steps:
- echo 'step'
staging:
steps:
- echo 'step'
but could it be something like
但它可能是这样的
pipelines:
branches:
rev|staging:
steps:
- echo 'step'
回答by RH Becker
A comma-separated list inside braces appears to work:
大括号内的逗号分隔列表似乎有效:
pipelines:
branches:
'{rev,staging}':
- step:
script:
- echo 'step'
回答by Max Malysh
This is a full example on how you can reuse somesteps:
这是一个关于如何重用某些步骤的完整示例:
image: yourimage:latest
definitions:
services: ... # Service definitions go there
steps:
- step: &Test-step
name: Run tests
script:
- npm install
- npm run test
- step: &Deploy-step
name: Deploy to staging
deployment: staging
script:
- npm install
- npm run build
- fab deploy
pipelines:
default:
- step: *Test-step
- step: *Deploy-step
branches:
master:
- step: *Test-step
- step:
<<: *Deploy-step
deployment: production
trigger: manual
Read more about YAML anchors: https://confluence.atlassian.com/bitbucket/yaml-anchors-960154027.html
阅读有关 YAML 锚点的更多信息:https: //confluence.atlassian.com/bitbucket/yaml-anchors-960154027.html
回答by Anthon
Instead of interpreting rev|staging
, a far more natural way of implementing that would be using a flow style sequence as a key:
而不是解释rev|staging
,一种更自然的实现方式是使用流样式序列作为键:
pipelines:
branches:
[rev, staging]:
- step:
script:
- echo 'step'
That would alleviates the need for quoting and for making sure spaces, or an extra (trailing) comma, make no semantic difference. Depending on the library that bitbucket uses to process this, the above might parse correctly, but not load (e.g. PyYAML cannot handle the above, but ruamel.yaml
). I have not been able to verify if this preferable way actually works in bitbucket.
这将减少对引用和确保空格或额外(尾随)逗号没有语义差异的需要。根据 bitbucket 用于处理此内容的库,上述内容可能会正确解析,但无法加载(例如,PyYAML 无法处理上述内容,但是ruamel.yaml
)。我无法验证这种更可取的方式是否真的适用于 bitbucket。
There are two ways that do work, one using the familiar YAML functionality of anchors and aliases to provide repeated (complex) data structures only once:
有两种方法可以奏效,一种是使用熟悉的 YAML 锚点和别名功能,仅提供一次重复(复杂)数据结构:
pipelines:
branches:
rev: &sharedsteps
- step:
script:
- echo 'step'
staging: *sharedsteps
The other possibility is, as others have indicated, to use some a non-standard, bitbucket specific, interpretation of scalar keys with embedded comma's. I have not found clear documentation on this, but the glob patternsseem applicable, so you can use {rev,staging}
as a key.
另一种可能性是,正如其他人所指出的,使用一些非标准的、特定于位桶的、对嵌入逗号的标量键的解释。我还没有找到关于此的明确文档,但glob 模式似乎适用,因此您可以将其 {rev,staging}
用作密钥。
What is ugly about this is that {
is the flow-style sequence indicator in YAML, so that scalar needs to be quoted:
丑陋的是,这是{
YAML 中的流样式序列指示符,因此需要引用标量:
pipelines:
branches:
"{rev,staging}":
- step:
script:
- echo 'step'
The above was updated using the corrected step syntax that BlueM provided
上面是使用 BlueM 提供的更正的步骤语法更新的
回答by BlueM
As requested by Anthon in a comment to his answer, this is his perfect solution, but with the correct YAML structure as expected by Bitbucket Pipelines:
正如 Anthon 在对他的回答的评论中所要求的,这是他的完美解决方案,但具有 Bitbucket Pipelines 预期的正确 YAML 结构:
pipelines:
branches:
rev: &sharedsteps
- step:
script:
- echo 'step'
staging: *sharedsteps
回答by Attila Csányi
With Bitbucket 5.8 in order to be able to manually trigger the pipeline I had to use this format:
在 Bitbucket 5.8 中,为了能够手动触发管道,我不得不使用这种格式:
pipelines:
branches:
rev,staging:
- step:
script:
- echo 'step'
So basically just comma separated branch list which need the same pipeline
所以基本上只是需要相同管道的逗号分隔分支列表