Hello,
Could someone please guide me on how to use YAML anchors for parallel steps to re-use sections of pipelines in branches?
I have provided a sample bitbucket-pipelines.yml below based on my scenario. As you can see, I have to repeat same steps for feature & master branches.
I know how to write the anchors for nromal sequential steps and I had initially referred to https://bitbucket.org/sonarsource/sample-nodejs-project/src/master/bitbucket-pipelines.yml for YAML anchors but don't know how to implement it for parallel steps.
Any help will be much appreciated. Thanks.
Sample bitbucket pipeline yml file -
I have tried formatting the yml file.
image: node:10.14
clone:
depth: full
definitions:
services:
docker:
memory: 2048
caches:
sonar: ~/.sonar/cache
pipelines:
branches:
feature-abc:
- step:
caches:
- node
- sonar
script:
- cd demo-proj
- npm install
artifacts:
- demo-proj/node_modules/**
- parallel:
- step:
name: Execute unit tests for xyz
script:
- cd demo-proj
- npm run test "xyz-directory" --codeCoverage=true --progress=true --watch=false
artifacts:
- demo-proj/coverage/**
- step:
name: Execute unit tests for abc
script:
- cd demo-proj
- npm run test "abc-directory" --codeCoverage=true --progress=true --watch=false
artifacts:
- demo-proj/coverage/**
- step:
name: Run SonarCloud Analysis
script:
- cd demo-proj
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources="src"'
master:
- step:
caches:
- node
- sonar
script:
- cd demo-proj
- npm install
artifacts:
- demo-proj/node_modules/**
- parallel:
- step:
name: Execute unit tests for xyz
script:
- cd demo-proj
- npm run test "xyz-directory" --codeCoverage=true --progress=true --watch=false
artifacts:
- demo-proj/coverage/**
- step:
name: Execute unit tests for abc
script:
- cd demo-proj
- npm run test "abc-directory" --codeCoverage=true --progress=true --watch=false
artifacts:
- demo-proj/coverage/**
- step:
name: Run SonarCloud Analysis
script:
- cd demo-proj
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources="src"'
Hi @Manish Kumar,
I built the following example that should speak by itself:
definitions:
step_def1: &myCommonStep1
name: Step1 name
script:
- echo "command 1"
- echo "command 2"
step_def2: &myCommonStep2
name: Step2 name
script:
- echo "command 3"
- echo "command 4"
pipelines:
default:
- parallel:
- step: *myCommonStep1
- step:
<<: *myCommonStep2
name: Step renamed
- step: *myCommonStep2
(i) The step renamed has only the intention to show a different way to declare the step inside the parallel section.
Please let me know if you face any issues to reproduce this configuration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome @Manish Kumar!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.