20

Does the build have to run on the drone.io server? Can I run the build locally? Since developers need to pass the build first before pushing code to github, I am looking for a way to run the build on developer local machine. Below is my .drone.yml file:

pipeline:
  build:
    image: node:latest
    commands:
      - npm install
      - npm test
      - npm run eslint
  integration:
    image: mongo-test
    commands:
      - mvn test

It includes two docker containers. How to run the build against this file in drone? I looked at the drone cli but it doesn't work in my expected way.

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • 9
    Yes `drone exec` is used to run your build locally and does not require a drone server connection. It is 100% local. Can you please provide more details as to why it does not work as expected and the steps to reproduce? Did you run the command from the root of your repository? Did you consult the documentation http://readme.drone.io/cli/drone-exec/ ? – Brad Rydzewski Jan 05 '17 at 02:14
  • Ok I see. I didn't check exec. I thought all the commands in drone is used to link to the drone server. Thanks for your help. – Joey Yi Zhao Jan 05 '17 at 02:20

1 Answers1

23

@BradRydzewski comment is the right answer.

To run builds locally you use drone exec. You can check the docs.

Extending on his answer, you must execute the command in the root of your local repo, exactly where your .drone.yml file is. If your build relies on secrets, you need to feed these secrets through the command line using the --secret or --secrets-file option.

When running a local build, there is no cloning step. Drone will use your local git workspace and mount it in the step containers. So, if you checkout some other commit/branch/whatever during the execution of the local build, you will mess things up because Drone will see those changes. So don't update you local repo while the build is running.

swenzel
  • 6,745
  • 3
  • 23
  • 37
Daniel Cerecedo
  • 6,071
  • 4
  • 38
  • 51
  • 2
    `drone exec` gives error for `type: exec`: `Stage '' not found in build file : resource not found` – ciekawy Feb 04 '23 at 18:18