Can not use yaml anchors in pipeline
Asked by Nativ Issac:

Hey All!

I'm pretty new to bitbucket pipelines, so the following may seem trivial but anyway..

Tryin to declare the following bitbucket-pipelines.yml file:

```
definitions:
  steps:
    - step: &black
      name: Black Format Check
      image: python:3.7
      script:
        - pip install black
        - black --check .
    - step: &mypy
      name: mypy Check
      image: python:3.7
      script:
        - pip install mypy
        - mypy src
    - step: &flake8
      name: flake8 Lint Check
      image: python:3.7
      script:
        - pip install flake8 flake8-bugbear
        - flake8 -v .
    - step: &pylint
      name: pylint Lint Check
      image: python:3.7
      script:
        - pip install pylint
        - pylint src


pipelines:
  pull-requests:
    feature/*:
      - parallel:
        - step: *black
        - step: *mypy
        - step: *flake8
        - step: *pylint
```

But the pycharm states that
> Schema validation: Property 'parallel' is not allowed

Interesting considering when checked using the [online validator](https://bitbucket-pipelines.prod.public.atl-paas.net/validator) I see it's valid :\\

Have I miss used yaml anchors?

Thanks in advance for your help :)


Answers:
author: Soumyadeep Mandal - SaM
body: Hi [@Nativ Issac](/t5/user/viewprofilepage/user-id/4240049) ,

Welcome to the community!

Will you please have a look at this documentation and follow it!

<https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/>

Some ore resources

<https://community.atlassian.com/t5/Bitbucket-questions/Help-with-YAML-anchors-for-parallel-steps-in-bitbucket-pipeline/qaq-p/1174674>

<https://community.atlassian.com/t5/Bitbucket-questions/Bitbucket-pipeline-using-multiple-anchors/qaq-p/1124020>

<https://community.atlassian.com/t5/Bitbucket-questions/Pipelines-Anchors-Aliases-for-Script-Command-Snippets/qaq-p/1051313>

Regards,

***Soumyadeep***

comments: author: Nativ Issac
body: [@Soumyadeep Mandal - SaM](/t5/user/viewprofilepage/user-id/4216583) Thanks a lot!

Appreciate your quick \& informative response :)

For the record, problem was that I declared the steps as list items.

Fix was to convert them to sub keys:

```
definitions:
    black-step: &black
      name: Black Format Check
      image: python:3.7
      script:
        - pip install black
        - black --check .
    mypy-step: &mypy
      name: mypy Check
      image: python:3.7
      script:
        - pip install mypy
        - mypy src
    flake8-step: &flake8
      name: flake8 Lint Check
      image: python:3.7
      script:
        - pip install flake8 flake8-bugbear
        - flake8 -v .
    pylint-step: &pylint
      name: pylint Lint Check
      image: python:3.7
      script:
        - pip install pylint
        - pylint src


pipelines:
  pull-requests:
    feature/*:
      - parallel:
        - step: *black
        - step: *mypy
        - step: *flake8
        - step: *pylint
```

Thanks again!


author: Francis Poulin
body: Hi [@Nativ Issac](/t5/user/viewprofilepage/user-id/4240049) ,

I'm currently facing an issue similar to yours and I'm not sure how your solution fixed the issue.

I understand that you changed your step definitions from an array to mapped objects, but this should't affect the referenced object.

In both exemple, \*black should have the same value.

++Note:++ I just saw that in your first example, the indentation for the step is wrong (i think)  

```
definitions:
  steps:
    - step: &black
      name: Black Format Check
```

Should be:

```
definitions:
  steps:
    - step: &black
        name: Black Format Check
```

Cheers,


author: Nativ Issac
body: [@Francis Poulin](/t5/user/viewprofilepage/user-id/3819177) Hi, thanks for letting me (and perhaps some more future readers) know.

Our pipelines are already implemented in the mapped objects approach and it does not bother me that much..

Have not checked your suggestion, but I hope it suites your needs.


Tags: bitbucket-cloud

bitbucket-pipelines

cloud