问题
I want to run our automated backend test suite on Google Cloud Builder environment. However, naturally, I bumped into the need to install various dependencies and prerequisites within the Cloud Builder so that our final test runner (php tests/run
) can run.
Here's my current cloudbuild.yaml:
steps:
- name: 'ubuntu'
args: ['bash', './scripts/install-prerequisites.sh', '&&', 'composer install -n -q --prefer-dist', '&&', 'php init --overwrite=y', '&&', 'php tests/run']
At the moment, the chaining of multiple commands doesn't work. The only thing that's executed is the bash ./scripts/install-prerequisites.sh
part. How do I get all of these commands get executed in order?
回答1:
You have 2 options to achieve this at the moment I believe:
- create a script that has the sequence of commands you'd like and call the script directly:
# cloudbuild.yaml
steps:
- name: 'ubuntu'
args: ['./my-awesome-script.sh']
# my-awesome-script.sh
/usr/bin/env/bash
set -eo pipefail
./scripts/install-prerequisites.sh
composer install -n -q --prefer-dist
php init --overwrite=y
php tests/run
- Call
bash -c
with all the commands you'd like to follow:
steps:
- name: 'ubuntu'
args: ['bash', '-c', './scripts/install-prerequisites.sh && composer install -n -q --prefer-dist && php init --overwrite=y && php tests/run']
回答2:
A more readable way to run the script could be to use breakout syntax (source: mastering cloud build syntax)
steps:
- name: 'ubuntu'
entrypoint: 'bash'
args:
- '-c'
- |
./scripts/install-prerequisites.sh \
&& composer install -n -q --prefer-dist \
&& php init --overwrite=y \
&& php tests/run
However, this only works if your build step image has the appropriate deps installed (php, composer).
回答3:
See:
- https://cloud.google.com/cloud-build/docs/configuring-builds/configure-build-step-order
- https://cloud.google.com/cloud-build/docs/configuring-builds/store-images-artifacts
- https://github.com/GoogleCloudPlatform/cloud-builders-community
- https://github.com/GoogleCloudPlatform/cloud-builders
By default, build steps run sequentially, but you can configure them to run concurrently.
The order of the build steps in the steps field relates to the order in which the steps are executed. Steps will run serially or concurrently based on the dependencies defined in their waitFor fields.
A step is dependent on every id in its waitFor and will not launch until each dependency has completed successfully.
So you only separate command as each step.
Like this.
steps:
- name: 'ubuntu'
args: ['bash', './scripts/install-prerequisites.sh']
id: 'bash ./scripts/install-prerequisites.sh'
- name: 'ubuntu'
args: ['composer', 'install', '-n', '-q', '--prefer-dist']
id: 'composer install -n -q --prefer-dist'
- name: 'ubuntu'
args: ['php', 'init', '--overwrite=y']
id: 'php init --overwrite=y'
- name: 'ubuntu'
args: ['php', 'tests/run']
id: 'php tests/run'
By the way, Can using ubuntu image run php and composer command?
I think that you should use or build docker image which can run php and composer command.
The composer docker image is here.
steps: - name: 'gcr.io/$PROJECT_ID/composer' args: ['install']
来源:https://stackoverflow.com/questions/55863128/multiple-commands-in-the-same-build-step-in-google-cloud-builder