# How to skip custom clone step for drone exec

**URL:** <https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357>\
**Category:** Drone Support\
**Created:** [May 29, 2019, 12:39pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357 "2019-05-29T12:39:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chuangbo](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/chuangbo/32/4369_2.png) [@chuangbo](https://drone.discourse.group/u/chuangbo)\
**Post date:** [May 29, 2019, 12:39pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/1 "2019-05-29T12:39:02Z")

</div>

drone: 1.1.0

Our repo disabled default clone and added a custom step named ‘clone’.

```auto
clone:
  disable: true

steps:
  clone:
    ...

```

But when I tried to run `drone exec --exclude clone` to test locally, the `clone` step still ran. Am I doing anything wrong?

---

<div class="post-metadata">

**Author:** ![david-l-riley](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/david-l-riley/32/5917_2.png) [@david-l-riley](https://drone.discourse.group/u/david-l-riley)\
**Post date:** [May 7, 2020, 3:21pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/2 "2020-05-07T15:21:03Z")

</div>

I’m having this same issue using 1.2.0, FWIW. This is a problem since we keep the secrets to clone the repository in our Drone server, and we don’t particularly want to replicate them on the local client since it’s already cloned. I suspect it’s probably a bug where the custom clone step is added _after_ the steps are excluded, I’ll poke through the source and see if it makes sense to file a PR.

---

<div class="post-metadata">

**Author:** ![david-l-riley](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/david-l-riley/32/5917_2.png) [@david-l-riley](https://drone.discourse.group/u/david-l-riley)\
**Post date:** [May 7, 2020, 3:22pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/3 "2020-05-07T15:22:46Z")

</div>

I suspect we could work around this by defining different “feeder” pipelines to the main build pipeline, one of which includes the custom clone and one which doesn’t, but that seems like a really gross hack to work around what’s probably a bug.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [May 7, 2020, 3:58pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/4 "2020-05-07T15:58:06Z")

</div>

The default clone step is automatically disabled by the CLI when run locally:

> <https://github.com/drone/drone-cli/blob/master/drone/exec/exec.go#L206:L211>

Using the following yaml:

```nohighlight
kind: pipeline
type: docker
name: default

steps:
- name: greeting
  image: alpine:3.4
  commands:
  - echo hello

```

We see the clone does not execute:

```nohighlight
$ drone exec
[greeting:0] + echo hello
[greeting:1] hello

```

We can optionally execute clone locally:

```nohighlight
$ export DRONE_COMMIT_BRANCH=master
$ export DRONE_COMMIT_SHA=dac60baf1bd8a18c4f2c1c51baae5148bfcef3ce 
$ export DRONE_REMOTE_URL=https://github.com/drone/hello-world.git
$ drone exec --clone

[clone:0] Initialized empty Git repository in /drone/src/.git/
[clone:1] + git fetch origin +refs/heads/master:
[clone:2] From https://github.com/drone/hello-world
[clone:3] * branch master -> FETCH_HEAD
[clone:4] * [new branch] master -> origin/master
[clone:5] + git checkout dac60baf1bd8a18c4f2c1c51baae5148bfcef3ce -b master
[clone:6] Already on 'master'
[greeting:0] + echo hello
[greeting:1] hello

```

**EDIT** I see, this looks like it refers to when the default clone is disabled in the yaml and you define your own custom clone step directly in the pipeline? Yes, it looks like this is an edge case that is not accounted for in the CLI (if you rename the step from `clone` to something else, e.g. `fetch`, the exclude flag works as expected)

---

<div class="post-metadata">

**Author:** ![david-l-riley](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/david-l-riley/32/5917_2.png) [@david-l-riley](https://drone.discourse.group/u/david-l-riley)\
**Post date:** [May 7, 2020, 7:19pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/5 "2020-05-07T19:19:51Z")

</div>

Correct, but then if the clone stage is named something else, it doesn’t kick in on the server, so it can’t be cloned.

I’m fine with that not _automatically_ being disabled, though it’s probably better if it’s consistent with the behavior in re: the default clone, which is disabled. But the fact that it can’t be disabled with an explicit `--exclude` is a problem.

It looks like I can work around it with Jsonnet or Starlark, but I’ll see if I can find where the issue is in the source and submit a PR if those are welcome.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [May 7, 2020, 9:56pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/6 "2020-05-07T21:56:21Z")

</div>

> [@On another topic](https://drone.discourse.group/t/4713/5):
>
> Correct, but then if the clone stage is named something else, it doesn’t kick in on the server, so it can’t be cloned.

hmm, this is not accurate, there is no requirement that the custom clone step needs to be named _clone_ in order to execute on the server. That aside, I agree that the exclude logic should be fixed to resolve this particular edge case.

---

<div class="post-metadata">

**Author:** ![david-l-riley](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/david-l-riley/32/5917_2.png) [@david-l-riley](https://drone.discourse.group/u/david-l-riley)\
**Post date:** [May 8, 2020, 1:47pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/7 "2020-05-08T13:47:21Z")

</div>

Oh wait, that’s interesting, the documentation could probably use some clarification on this. If I’m interpreting this correctly, the `clone` step gets executed anyway because it’s the first step in the pipeline (no matter what it’s named), and it’s only forcibly executed when called `clone` because of said edge case? That makes some sense. I’ll try that out.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [May 8, 2020, 2:22pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/8 "2020-05-08T14:22:20Z")

</div>

Let me try to clarify.

When the server executes a pipeline:

1. Drone automatically prepends a clone step, named _clone_, to your pipeline
2. You disabled this behavior by adding clone: { disable: true } to your yaml
3. You added a step to your pipeline to perform the clone. You happened to name the step _clone_.
4. Drone treats all steps the same. It does not treat your user-defined _clone_ step any differently despite its name. As far as Drone is concerned this is just another step.

When the command line tools execute a pipeline:

1. The command line tools _do not_ automatically prepend a clone step because it mounts your current working directory to access the code.
2. Because Drone treats all steps the same, it does not automatically disable your user-define _clone_ step. As far as Drone is concerned this is just another step.
3. The _–exclude_ flag is used to disable user-defined steps. This should have worked but for whatever reason the exclude function was coded to ignore any attempts to exclude steps named _clone_ [1]. Looking back I have no clue why added this restriction …

The reason I refer to this as an edge case is because it only impacts pipelines running locally, with a user-defined step named _clone_, trying to use _–exclude=clone_. This is a bug that should be fixed.

However, what I really wanted to clarify is that user-defined steps with the name _clone_ are no different than any other pipeline step, and receive no special treatment from Drone (other than this bug with --exclude).

[1] [https://github.com/drone/drone-yaml/blob/master/yaml/compiler/transform/filter.go#L44:L67](https://github.com/drone/drone-yaml/blob/master/yaml/compiler/transform/filter.go#L44:L67)

---

<div class="post-metadata">

**Author:** ![david-l-riley](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/david-l-riley/32/5917_2.png) [@david-l-riley](https://drone.discourse.group/u/david-l-riley)\
**Post date:** [May 8, 2020, 2:53pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/9 "2020-05-08T14:53:38Z")

</div>

Right, it does make sense, other than the “why” of it, like you said. Since the main content of that file is all just the initial commit, `git blame` isn’t much help there. 🙂

Perhaps I’m reading the docs wrong, but they sort of implied that the step should be named “clone” since it’s custom clone logic. It makes much more sense that it’s not a special case… you could probably really simply elide that issue without even adding much/any additional commentary by calling it something else in the doc example like `my_custom_clone` or something?

---

<div class="post-metadata">

**Author:** ![ashwilliams1](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/ashwilliams1/32/5549_2.png) [@ashwilliams1](https://drone.discourse.group/u/ashwilliams1)\
**Post date:** [May 8, 2020, 2:55pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/10 "2020-05-08T14:55:51Z")

</div>

Good point, we should update the docs and name the step `fetch` to avoid any confusion, and then add some sort of note indicating that it is just a plain old step and can be named whatever. Thanks for the feedback.

---

<div class="post-metadata">

**Author:** ![david-l-riley](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/david-l-riley/32/5917_2.png) [@david-l-riley](https://drone.discourse.group/u/david-l-riley)\
**Post date:** [May 8, 2020, 3:24pm UTC](https://drone.discourse.group/t/how-to-skip-custom-clone-step-for-drone-exec/11357/11 "2020-05-08T15:24:23Z")

</div>

Absolutely! I’m not trying to come across as too harsh, apologies if that’s the case. Y’all have done a great job with Drone and I’m very happy to be able to be ditching Jenkins for good! I know this is sometimes a thankless task, so thanks very much for keeping up with things so quickly.
