How to reuse code from "script" on bitbucket-pipelines.yml?
Asked by Carol:

Hello community,

I'm trying to configure bitbucket-pipelines.yml to deploy to another remote. The file is Valid according to the <https://bitbucket-pipelines.prod.public.atl-paas.net/validator>.

However, I'm getting "Configuration error".

![bb_pipelines.png](https://community.atlassian.com/t5/image/serverpage/image-id/179819i3FEAAC2A7F1262A6/image-size/large?v=v2&px=999 "bb_pipelines.png")

Here's the yml:

```
# Ideally use an image with php, php extensions & composer.
# i.e. image: imagexmedia/ci:latest
# See: https://confluence.atlassian.com/bitbucket/php-with-bitbucket-pipelines-873907835.html
image: lbausch/laravel-ci:php81

# Defines single re-usable scripts.
script_definitions:
  scripts:
    env-setup: &env-setup
      - export BIN_DIR=$BITBUCKET_CLONE_DIR/vendor/bin
    composer-tasks: &composer-tasks
      - composer self-update --2
      - composer install --no-interaction --optimize-autoloader
    compile-assets-dev: &compile-assets-dev
      - npm install
      - npm run dev
    compile-assets-prod: &compile-assets-prod
      - npm install
      - npm run prod
    remote-push: &remote-push
      - git config --global user.name bitbucket-pipelines
      - git config --global user.email commits-noreply@bitbucket.org
      - git remote add platformsh q4wbvsyds6mfm@git.ca-1.platform.sh:q4wbvsyds6mfm.git
      - git checkout $BITBUCKET_BRANCH
      - git add --all
      - git commit -m"Bitbucket build - $BITBUCKET_BUILD_NUMBER, Commit $BITBUCKET_COMMIT"
      - git push platformsh $BITBUCKET_BRANCH

# Defines re-usable steps.
step_definitions:
  - validate: &validate
      name: 'Validation Tasks.'
      caches:
        - composer
      script:
        - *env-setup
        - *composer-tasks
        - ${BIN_DIR}/phpcs --standard=./phpcs.xml -p
  - deploy-branch: &deploy-branch
      name: 'Deploy branch to remote.'
      caches:
        - composer
      script:
        - *env-setup
        - *composer-tasks
        - *compile-assets-dev
        - *remote-push
  - deploy-prod: &deploy-prod
      name: 'Deploy branch to remote (PROD).'
      caches:
        - composer
      script:
        - *env-setup
        - *composer-tasks
        - *compile-assets-prod
        - *remote-push

# Bitbucket pipeline definitions.
pipelines:
  default:
    - step: *validate
  pull-requests:
    '**':
      - step: *validate
  branches:
    main:
      - step: *validate
      - step: *deploy-prod
    stage:
      - step: *validate
      - step: *deploy-branch
    develop:
      - step: *validate
      - step: *deploy-branch
```

Can you please help me to create some reusable "steps" under the "script"?

Thanks,  
Carol


Answers:
author: Dan Morrison
body: It works fine for me. I think the problem is how you're defining the anchors.

Instead of this:

```
script_definitions:
  scripts:
    env-setup: &env-setup
      - export BIN_DIR=$BITBUCKET_CLONE_DIR/vendor/bin
```

Try this:

```
script_definitions:
  scripts:
    - &env-setup export BIN_DIR=$BITBUCKET_CLONE_DIR/vendor/bin
```


author: Caroline R
body: Hi, [@Carol](/t5/user/viewprofilepage/user-id/4725424), welcome to the community!

Currently, script definitions are not supported. We do have a feature request to add the ability to use script entity for YAML anchors as you can see here:

* <https://jira.atlassian.com/browse/BCLOUD-20417>

I would suggest that you add your vote there (by selecting the **Vote for this issue** link) as the number of votes helps the development team and product managers better understand the demand for new features.

You are more than welcome to leave any feedback, and you can also add yourself as a watcher (by selecting the **Start watching this issue** link) if you'd like to get notified via email on updates.

Implementation of new features is done as per our policy [here](https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html) and any updates will be posted in the feature request.

With that said, I believe the following link might help you to change your YAML file:

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

I hope this helps!

Kind regards,   
Caroline


author: Admin Admin
body: what is the error message?

comments: author: Carol
body: This is the error on the Pipelines UI

*There is an error in your bitbucket-pipelines.yml at \[pipelines \> branches \> main \> 0 \> step \> script \> 0\]. To be precise: This section should be a string or a map (it is currently defined as a list).*

![bb_pipelines.png](https://community.atlassian.com/t5/image/serverpage/image-id/179818i63E3AD2BCBDE6DC3/image-size/large?v=v2&px=999 "bb_pipelines.png")


Tags: bitbucket-cloud

cloud