In my project I try to package my app:
image: php:8.1
pipelines:
default:
- step:
caches:
- composer
script:
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- php -r "unlink('composer-setup.php');"
- chmod +x /usr/local/bin/composer
- step:
caches:
- composer
script:
- export PATH=/usr/local/bin:$PATH
- composer install
- ./vendor/bin/phpunit
- step:
caches:
- composer
script:
- export PATH=/usr/local/bin:$PATH
- composer install --no-dev
- apt-get update && apt-get install -y zip
- export FILE=release-$(date +"%Y%m%d%H%M%S").zip
- zip ${FILE} ./lib/*.php ./vendor/* composer.json composer.lock index.php config.php ./utils/*.php
- curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${FILE}"
artifacts:
- release-$(date +"%Y%m%d%H%M%S").zip
But at step:
- step:
caches:
- composer
script:
- export PATH=/usr/local/bin:$PATH
- composer install
- ./vendor/bin/phpunit
I get the error:
bash: composer: command not found
Do you know why? Is seems like for some reason between each steps the installed composer is not shared.
caches: composerdoesn't mean composer itself is shared, it means composer's cache is shared. Each step is run in its own standalone container, so if you're going to use composer in each, then you have to install composer in each. In your example, your first step does nothing -- it just starts a container, installs composer, and then throws the container away. You could have two steps, one to test and one to build the zip, each installing and running composer:Alternatively, you could build your own custom image based on
php:8.1, with composer and zip already installed -- and then reference that in your pipe config.