Google Cloud Build: Moving files

I want to move the file index.js from the root of the project to the dist/project_name. This is the step from cloudbuild.yaml:

  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: /bin/bash
    args: ['-c', 'mv', 'index.js', 'dist/project_name']

But the step is failing with the next error:

Already have image (with digest): gcr.io/cloud-builders/docker
mv: missing file operand
Try 'mv --help' for more information.

How I can fix this issue?

1 answer

  • answered 2021-10-24 16:07 DazWilkin

    Because you're using bash -c, I think you need to encapsulate the entire "script" in a string:

    args: ['-c', 'mv index.js dist/project_name']
    

    My personal preference (and it's just that), is to not embed JSON ([...]) in YAML. This makes the result in this case slightly clearer and makes it easier to embed a multiline script:

    args:
    - bash
    - -c
    - |
      mv index js dist/project_name
    

    NOTE tools like YAMLlint will do this for you too.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum