Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to reuse code from "script" on bitbucket-pipelines.yml?

Carol January 24, 2022

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

 

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

3 answers

0 votes
Dan Morrison July 18, 2022

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
0 votes
Caroline R
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 31, 2022

Hi, @Carol, 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:

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 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:

I hope this helps!

Kind regards,
Caroline 

0 votes
Admin Admin January 25, 2022

what is the error message?

Carol January 25, 2022

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

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events