You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GCP Remote Builder示例配置中执行多条命令?

How to Run Multiple Commands in GCP Remote Builder Configuration

Got it, let's figure out how to run multiple commands in your existing GCP Remote Builder setup. There are two clean ways to do this—pick the one that fits your workflow best:

1. Chain Commands Directly in the COMMAND Field

You can wrap your multiple commands in a bash -c call, using either semicolons (;) to run commands sequentially regardless of success, or double ampersands (&&) to only run the next command if the previous one succeeded.

Here's how your updated configuration would look:

- name: gcr.io/$PROJECT_ID/remote-builder 
  waitFor: ["-"] 
  env: 
    # Use Container Optimized OS 
    - INSTANCE_ARGS=--image-project cos-cloud --image-family cos-stable 
    - ZONE=us-central1-f 
    - USERNAME=cloud-user 
    # Run multiple chained commands inside the Docker container
    - COMMAND=docker run -v /home/cloud-user/workspace:/workspace ubuntu:16.04 bash -xe -c "cd /workspace; ./test-scripts/no-op.sh; echo 'First command finished'; ./test-scripts/another-script.sh"
  • Use ; if you want all commands to run even if one fails.
  • Swap ; for && if you want the sequence to stop if any command fails.

2. Use a Local Script File (Better for Complex Sequences)

If you have a lot of commands or want to keep your configuration clean, put all your steps into a single local script file, then reference that script in the COMMAND field.

First, create a script (e.g., test-scripts/multi-step.sh) in your build context with all your commands:

#!/bin/bash
set -xe

cd /workspace
./test-scripts/no-op.sh
echo "Completed first script"
./test-scripts/another-script.sh
# Add as many commands as you need here

Then update your Remote Builder configuration to run this script:

- name: gcr.io/$PROJECT_ID/remote-builder 
  waitFor: ["-"] 
  env: 
    # Use Container Optimized OS 
    - INSTANCE_ARGS=--image-project cos-cloud --image-family cos-stable 
    - ZONE=us-central1-f 
    - USERNAME=cloud-user 
    # Run the multi-step script from your build context
    - COMMAND=docker run -v /home/cloud-user/workspace:/workspace ubuntu:16.04 bash -xe /workspace/test-scripts/multi-step.sh

This approach is easier to maintain, especially if you need to adjust or expand your command sequence later.

内容的提问来源于stack exchange,提问作者Shashikumar KL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:58:23