Reputation: 3579
ubuntu returns expected results from ls
until I add a cd
command then it returns nothing.
Here's a truncated outline of my project structure:
gcp_cicd_workflow
|-- src
| my_module.py
|-- tests
| test_my_module.py
The log messages I'm providing below are ordered with the newest on top. Note that there's a lot of ubuntu log messages related to pulling the image that I have excluded from the log messages.
Code:
# Step 4
- name: 'ubuntu'
entrypoint: '/bin/bash'
args: ['-c', 'ls']
Log The ls
command returns the expected results - it returns all the folders and files in the workspace folder:
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
Code:
# Step 4
- name: 'ubuntu'
entrypoint: '/bin/bash'
args: ['-c', 'cd tests', 'ls']
Log: No results returned after the cd
command:
Finished Step #4
Code - cd to nonexistent folder:
# Step 4
- name: 'ubuntu'
entrypoint: '/bin/bash'
args: ['-c', 'cd foo']
Log - Get expected "no such file ... "result):
Finished Step #4
Step #4: /bin/bash: line 0: cd: foo: No such file or directory
Upvotes: 0
Views: 520
Reputation: 30083
@Christopher Janzon answer is perfect you can also do it without entrypoint
here is a simple example
- id: 'set scripts_version'
name: 'ubuntu'
args: ['bash','-c','sed -i "s,SCRIPTS_VERSION_VALUE,$SHORT_SHA," k8s/*.yaml']
Upvotes: 0
Reputation: 1039
Try below code:
- name: 'ubuntu'
entrypoint`enter code here`: '/bin/bash'
args: ['-c', 'cd tests; ls']
$ bash -c
runs passed arguments as a single bash script. It doesn't separate passed arguments into separate scripts.
;
in bash ends a script line, and the following after semicolon is interpreted as a new script line.
Upvotes: 3