Cp doesn't overwrite files when executed on CircleCI

From my .circle/config.yml file I have a run statement like this:

pre-steps:
  - run:
    command: cp .env.dev .env

On the file system where this command is executed on CircleCI servers there is an existing .env file, and this file should be overwritten by .env.dev. However this overwrite doesn’t happen. No log message. No exit code 1. No error:

#!/bin/bash -eo pipefail
cp .env.dev .env

CircleCI received exit code 0

Simply, the file isn’t overwritten and the rest of .config.yml carries on normally, unlike when I do the same cp .env.dev .env on my local machine where the file is properly overwritten.

This happens on all our repositories that have a pipeline on CircleCI.

Any ideas?

try to create shell .sh file and call it as command

I ran into a similar situation where it appeared as if CircleCI wasn’t copying files. My issues was related to using the AWS ECR Orb (CircleCI Developer Hub - circleci/aws-ecr), specifically the following action:

      # Build and push image using orb.
      - aws-ecr/build-and-push-image:
          dockerfile: .docker/python/Dockerfile

By default, this orb checks out the code again (not sure why), but you can overwrite that behavior by setting the checkout flag to false.

That did the trick for me.