Handling errors in Bitbucket pipelines

Marten van Urk
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 23, 2018

Our php artisan migrate fails without a clear error on screen .So I want to tail the laravel log afterwards. But the script calls the teardown without the laravel log....

 

How can I tail logs after the build fails?

 

My bitbucket-pipelines

image: php:7.1.1

pipelines:
default:
- step:
services:
- mysql
deployment: test
caches:
- composer
script:
- apt-get update && apt-get install -y unzip
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- docker-php-ext-install pdo_mysql
- cp php.ini /usr/local/etc/php/php.ini
- composer install
- php -r "copy('.env.testing', '.env');"
- php --ini
- ls /usr/local/etc/php/
- export DB_CONNECTION=mysql
- composer dump-autoload
- php artisan migrate:install
- php artisan cache:clear
- php artisan migrate
- tail storage/logs/laravel.log -n 100

definitions:
services:
mysql:
image: mysql:5.7.22
entrypoint: ['/entrypoint.sh', '--character-set-server=utf8', '--collation-server=utf8_general_ci']
environment:
MYSQL_DATABASE: '********'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: '***********'
MYSQL_PASSWORD: '************'



1 answer

1 vote
SebC
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 25, 2018

Hey @Marten van Urk,

the simplest way is to combine the two commands using the bash built-in ||

- php artisan migrate || tail storage/logs/laravel.log -n 100

the downside is the exit code is lost, meaning your build will always pass.

If you want to keep this and track the exit code, the command is a bit uglier.

bash -c 'php artisan migrate; RET=$?; tail storage/logs/laravel.log -n 100; exit $RET'

 Hope that helps,

Seb

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events