Step with mkdir successful, but directory not created

New CircleCI user here. I’ve been struggling trying to execute a mkdir command. The step exits successfully in my workflow, but the folder is not created. I’m unable to locate it anywhere in the file system.

Here’s my config.yml file, up to and including the step in question. I removed the rest for the sake of brevity. Note: Changing the shell was another troubleshooting step, though it yielded the same (missing) result.

version: 2
        - staging
    working_directory: ~/build
      - image: circleci/php:7.2-node-browsers

      - checkout

      - run: 
          name: APT Installs (ZIP, PDO, MySQL, Composer)
          command: |        
            sudo docker-php-ext-install zip
            sudo docker-php-ext-install pdo pdo_mysql
            sudo apt-get install software-properties-common
            sudo composer self-update

      - run: 
          name: Install Python and PIP
          command: |
            sudo apt-get install -y python3.7
            sudo apt install -y python3-pip
            sudo pip3 install --upgrade pip
            sudo pip3 install --upgrade awscli
            sudo pip3 install --upgrade awsebcli
      - run:
          name: Create Image Directory (if not exists)
          command: |            
            sudo mkdir -m 0755 -p /var/user_image

Here’s a screenshot from the build:

Hmm, OK. Can you add a ls -l /var/user_image as a second line to the last run step?

Check the stdout in the build logs too, in case there is a filing system or parameter error. Edit: ah, it comes back with Unix code zero - which is fine.

@halfer thanks for taking a look.

Here’s the result:

#!/bin/bash -eo pipefail 
sudo mkdir -m 0755 -p /var/user_image 
ls -l /var/user_image
total 0 

Exited with code 0 and the full workflow completed. It appears the directory is being created, although I don’t know what happens after that.

Perhaps my config has it treated as a temporary directory only? I wouldn’t have thought so, given what I’ve seen in my research (e.g., stalking other people’s configs), but perhaps I missed something critical.

Hmm, not seen that before. You’re in a Docker container, so there might be some permission issues. I would suggest dropping the -m temporarily, and perhaps the sudo too.

In fact I wonder if you could take out all of the sudo from this config - your runtime user should have enough permissions to install things without that.

I just realized the problem: it was one of expectations. I AM a newb, after all! I was looking for the directory on the production server, but telling CircleCI to build it in the container. Well, no wonder I couldn’t find it in the server!

I believe what I need to do now is figure out how to SSH into the production server from my container during the workflow, then create the folder.

Will report back.

In the end, I over-complicated this and misunderstood the process.

My goal was to create a directory on my application server, which was hosted in Elastic Beanstalk. Although I wanted to create the directory on the server, the commands I was using in my config.yml file were creating the directory in the container. CircleCI behaved perfectly fine. I didn’t!

Instead, I simply needed to add the command to the config file located in my .ebextensions source folder.

Here’s the full config file from the .ebextensions folder, for anyone else who runs across this.

        owner: root
        group: root
        mode: "000600"
        content: |
                User git
                IdentityFile /root/.ssh/battlestardigitalbot-github-deploy
        owner: root
        group: root
        mode: "000644"
        content: |

        command: sudo aws s3 cp s3://battlestar-deployment-key/battlestardigitalbot-github-deploy /root/.ssh
        command: sudo chmod 600 /root/.ssh/battlestardigitalbot-github-deploy
        command: sudo mkdir -m 0755 -p /var/user_image
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.