Bitbucket piping - multiple branches with the same steps

Is it possible to combine several branches that have the same steps in bitpack pipeline?

ex: The teams I'm working on use one of two names for their view branches: "rev" or "staging". In any case, these same steps are used to publish a review on our server. Right now the branches are being called separately.

pipelines: branches: rev: steps: - echo 'step' staging: steps: - echo 'step' 

but maybe something like

 pipelines: branches: rev|staging: steps: - echo 'step' 
+12
source share
5 answers

A list is displayed, separated by commas inside curly braces:

 pipelines: branches: '{rev,staging}': - step: script: - echo 'step' 
+22
source

Instead of interpreting rev|staging , a much more natural implementation method that will use a sequence of stream styles as a key:

 pipelines: branches: [rev, staging]: - step: script: - echo 'step' 

This will eliminate the need for quotation marks and that spaces or an extra (comma) comma do not make sense difference. Depending on the library that bitbucket uses for processing, the above may be correctly analyzed but not loaded (for example, PyYAML cannot process the above, but ruamel.yaml ). I have not been able to check if this preferred method really works in bitbucket.

There are two ways to work, one of which uses the familiar YAML functionality of anchors and aliases to provide repetitive (complex) data structures only once:

 pipelines: branches: rev: &sharedsteps - step: script: - echo 'step' staging: *sharedsteps 

Another possibility, as others have already pointed out, is to use some non-standard interpretation of scalar keys with the bitbucket specification with embedded commas. I did not find clear documentation on this, but the glob patterns seem to be applicable, so you can use {rev,staging} as the key.

Whatโ€™s scary about this is that { this is a sequence indicator in YAML, so you must enclose the scalar in quotation marks:

 pipelines: branches: "{rev,staging}": - step: script: - echo 'step' 

The above has been updated using the revised step syntax provided by BlueM

+7
source

As requested by Anton in the commentary on his answer, this is his ideal solution, but with the correct YAML structure, as expected in Bitbucket Pipelines:

 pipelines: branches: rev: &sharedsteps - step: script: - echo 'step' staging: *sharedsteps 
+2
source

With Bitbucket 5.8, in order to be able to manually start the pipeline, I had to use this format:

 pipelines: branches: rev,staging: - step: script: - echo 'step' 

So basically just a comma-separated list of branches that need the same pipeline

+2
source

This is a complete example of how you can use several steps:

 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 

Learn more about YAML anchors: https://confluence.atlassian.com/bitbucket/yaml-anchors-960154027.html

+1
source

Source: https://habr.com/ru/post/1264357/


All Articles