Cloning

Updated 2 years ago by Admin

Drone automatically clones your repository before executing your pipeline steps. No special configuration is required. In some cases, however, you may need to customize, override or disable the default clone behavior.


The --depth flag

The default clone configuration does use the --depth flag. You can enforce a clone depth by declaring a clone block and adding the depth attribute:

1  kind: pipeline
2 type: macstadium
3 name: default
4
5 clone:
6 depth: 50
7
8 steps:
9 - name: build
10 commands:
11 - go build
12 - go test

The --tags flag

The default clone configuration does not use the --tags flag. If you would like to fetch tags you should handle this as a step in your pipeline. For example:

1  kind: pipeline
2 type: macstadium
3 name: default
4
5 steps:
6 - name: fetch
7 commands:
8 - git fetch --tags
9
10 - name: build
11 commands:
12 - go build
13 - go test

The --recursive flag

The default clone behavior does not use the --recursive flag and does not fetch submodules. If you would like to fetch submodules you should handle this as a step in your pipeline. For example:

1  kind: pipeline
2 type: macstadium
3 name: default
4
5 steps:
6 - name: submodules
7 commands:
8 - git submodule update --recursive --remote
9
10 - name: build
11 commands:
12 - go build
13 - go test

Custom Logic

The default clone behavior can be disabled and custom clone logic implemented, when necessary. In the following example we implement custom clone commands as a pipeline step:

1  kind: pipeline
2 type: macstadium
3 name: default
4
5 clone:
6 disable: true
7
8 steps:
9 - name: clone
10 commands:
11 - git clone https://github.com/octocat/hello-world.git .
12 - git checkout $DRONE_COMMIT
13
14 - name: build
15 commands:
16 - go build
17 - go test


How did we do?