GCP Cloud Build ubuntu 步骤成功运行,但没有预期的结果



ubuntu 从ls返回预期结果,直到我添加一个cd命令,然后它什么也不返回。

以下是我的项目结构的截断大纲:

gcp_cicd_workflow
|-- src
| my_module.py
|-- tests
| test_my_module.py

我在下面提供的日志消息按最新的顺序排列。请注意,有很多与拉取我从日志消息中排除的映像相关的 ubuntu 日志消息。

法典:

# Step 4
- name: 'ubuntu'
entrypoint: '/bin/bash'
args: ['-c', 'ls']

日志ls命令返回预期的结果 - 它返回工作区文件夹中的所有文件夹和文件:

Finished Step #4
Step #4: tests
Step #4: src
Step #4: setup.py
Step #4: requirements.txt
Step #4: python_cloud_builder
Step #4: gcp_cicd
Step #4: gcp.egg-info
Step #4: gcp-cicd-workflow
Step #4: cloudbuild.yaml
Step #4: __init__.py
Step #4: README.md

法典:

# Step 4
- name: 'ubuntu'
entrypoint: '/bin/bash'
args: ['-c', 'cd tests', 'ls']

日志:cd命令后未返回任何结果:

Finished Step #4

代码 - cd 到不存在的文件夹:

# Step 4
- name: 'ubuntu'
entrypoint: '/bin/bash'
args: ['-c', 'cd foo']

日志 - 获得预期的"没有这样的文件..."结果(:

Finished Step #4
Step #4: /bin/bash: line 0: cd: foo: No such file or directory

尝试以下代码:

- name: 'ubuntu'
entrypoint`enter code here`: '/bin/bash'
args: ['-c', 'cd tests; ls']

$ bash -c将传递的参数作为单个 bash 脚本运行。它不会将传递的参数分隔到单独的脚本中。

bash中的;结束脚本行,分号后面的以下内容被解释为新的脚本行。

@Christopher Janzon 答案很完美,你也可以不用entrypoint这里有一个简单的例子

- id: 'set scripts_version'
name: 'ubuntu'
args: ['bash','-c','sed -i "s,SCRIPTS_VERSION_VALUE,$SHORT_SHA," k8s/*.yaml']

最新更新