skip to Main Content

For my Laravel application, I have created a bitbucket-pipeline :

image: php:8.0
pipelines:
  branches:
    stage:
      - step:
          name: Install Dependencies
          caches:
            - composer
            - node
          script:
            - apt-get update && apt-get install -y unzip libpng-dev libjpeg-dev libfreetype6-dev
            - docker-php-ext-configure gd --with-freetype --with-jpeg
            - docker-php-ext-install gd
            - curl -sS https://getcomposer.org/installer | php
            - mv composer.phar /usr/local/bin/composer
            - composer install --no-scripts
            - curl -sL https://deb.nodesource.com/setup_16.x | bash -
            - apt-get install -y nodejs
            - npm install --legacy-peer-deps
      - step:
          name: Run Tests
          script:
            - vendor/bin/phpunit
      - step:
          name: Build Assets
          caches:
            - node
          script:
            - npm run prod
      - step:
          name: Migrate Database
          script:
            - php artisan migrate --force
            - php artisan key:generate
            - php artisan jwt:secret
          services:
            - mysql

definitions:
  services:
      mysql:
      image: mysql:5.7

caches:
  composer: ~/.composer/cache
  node: ~/.npm

So far so good, but when I run this, I get the error:

bash: vendor/bin/phpunit: No such file or directory

I checked that the folder exist and everything is fine, but i still get the error.

can someone help me out?

2

Answers


  1. Try use absolute path.

    /var/www/your-project/vendor/bin/phpunit
    

    I think that step "Run Tests" must be after "Migrate Database".

    Login or Signup to reply.
  2. Exercise for the reader: link all questions regarding this recurring confusion.


    Each pipeline steps happens in a pristine docker container. Thus, the installation instructions of any tooling must be repeated in every and each step using that tooling! You must not rely on caches making software available, caches are solely meant to speed-up the install instructions, but aren’t guaranteed to be present (e.g. think about re-running a step after a cache has been cleared or expired).

    From https://support.atlassian.com/bitbucket-cloud/docs/cache-dependencies/#Best-practices

    Remember that caches are temporary, so your builds should be configured to work whether or not the cache is present.

    definitions:
      services:
        mysql:
          image: mysql:5.7
    
    caches:
      composer: ~/.composer/cache
      node: ~/.npm
    
    pipelines:
      branches:
        stage:
          - step:
              name: Run Tests
              image: composer:2
              caches: [composer]
              script:
                - composer install --no-scripts
                - vendor/bin/phpunit
          - step:
              image: node:18
              name: Build Assets
              caches: [node]
              script:
                - npm install --legacy-peer-deps
                - npm run prod
          - step:
              name: Migrate Database
              image: composer:2
              caches: [composer]
              script:
                - composer install --no-scripts  # Yes, again
                - php artisan migrate --force
                - php artisan key:generate
                - php artisan jwt:secret
              services:
                - mysql
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search