How to skip cloning when there are cached files and perform cloning when there are no cached files

This is what I do now :

Is that ok?
Is there a better way? If anyone knows, please tell me. Thank you very much.

I have the same issues. Then I implemented it in a rather stupid way.

First, the commands cannot execute multi-line commands like this:

  - if [ ! s "xxx" ]; then
      git clone xxx
  - fi

You need to run a shell script file for multi-line commands:

  - /bin/sh

For example, my demo for cache repos:

  - name: restore-cache
    image: drillster/drone-volume-cache
  - name: get_depends
    image: drone/git
        from_secret: user_name
        from_secret: access_token
      - export CICD_PATH=_tmp_cicd
      - git clone https://$GIT_USERNAME:$
      - mv $DRONE_REPO_NAME/cicd ./$CICD_PATH
      - rm -rf $DRONE_REPO_NAME
      - echo "start download all depend repos"
      - /bin/sh ./$CICD_PATH/
      - rm -rf $CICD_PATH
  - name: rebuild-cache
    image: drillster/drone-volume-cache
  - name: test

repo files:

- demo
  - cicd
    - dep_repos
 - others

the dep_repos contains all dependent libraries:


for repo in $(cat ./$CICD_PATH/dep_repos); do

  # Get the name of the dependent library
  echo "the repo name is: ${repo_name}"

  # Determine if the dependent library is cached
  if [ ! -d "${repo_name}/.git" ]; then

    # no cached, download it
    echo "the repo ${repo_name} no cached, download it"
    git clone https://$GIT_USERNAME:$GIT_USERTOKEN@${repo}.git


    # cached, update it
    echo "the repo ${repo_name} cached, update it"
    cd ${repo_name}

    # Define the master branch as the latest available branch
    git pull origin master:master

    # Return to the parent directory
    cd ..


There should be better ways to achieve it, and I am constantly exploring it.