1

I am using Circleci to build and test typescript code. when code is pushed and Circleci starts building in a docker container, I noticed it ignores some hidden files (dot files) in the repository while copying to the container. I ensured that by adding ls command in one of steps. How to make Circleci copy .env from the code repository while copying the rest of the code files?

.circleci/config.yml

version: 2 # use CircleCI 2.0
jobs: # a collection of steps
  build: # runs not using Workflows must have a `build` job as entry point
    working_directory: ~/su-app-api # directory where steps will run
    docker: # run the steps with Docker
      - image: node:16-alpine3.16
    steps: # a collection of executable commands
      - checkout # special step to check out source code to working directory
      - add_ssh_keys:
          fingerprints:
              - "my finger print"

      - run: 
          name: ls
          command: ls -al && ls api -al

      - run:
          name: Install API Dependencies
          command: npm i

      - run:
          name: Build API
          command: npm run build:api
        
      - run:
          name: Test API
          command: npm run test

      - deploy:
          name: deployment
          command: ssh -o "StrictHostKeyChecking no" user_name@ip "cd ~/su-app-api && git pull origin deploy && sh deploy.sh"
  • 1
    Apart from the technical problem, consider to no inject the environment parameters via an `.env` file that you commit into your repository. Instead provide the build / CI environment via the circleci config. – hakre May 28 '23 at 18:57

1 Answers1

1

I found the problem. I was using the node-alpine image which has no shh-client or git installed. As a result, the checkout step in Circleci was falling back to CircleCI's native git client¹ but the behavior may be different from official git.

I added a step to install ssh and git before the checkout step and it worked normally.

      - run:
          name: install ssh and git
          command: apk add --update openssh-client git

¹ Checkout Code Step Outputs "Either git or ssh (required by git to clone through SSH) is Not Installed in the Image"

hakre
  • 193,403
  • 52
  • 435
  • 836
  • How do you know that circleci has a native git client? Can you provide reference? In the following circleci support document it is not mentioned, however it may be the scenario you're writing about: [CircleCI Support Center: Using CircleCI: Configuring Pipelines: **How do I modify the checkout step?** by Fernando; September 29, 2022](https://support.circleci.com/hc/en-us/articles/115015659247-How-do-I-modify-the-checkout-step-) – hakre May 28 '23 at 18:43
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 29 '23 at 03:49
  • @hakre Here you go https://support.circleci.com/hc/en-us/articles/360046718853-Checkout-Code-Step-Outputs-Either-git-or-ssh-required-by-git-to-clone-through-SSH-is-Not-Installed-in-the-Image- – Hossam Hamza Jun 01 '23 at 17:11