Cloning
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: kubernetes
3 name: default
4
5 clone:
6 depth: 50
7
8 steps:
9 - name: build
10 image: golang
11 commands:
12 - go build
13 - 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: kubernetes
3 name: default
4
5 steps:
6 - name: fetch
7 image: alpine/git
8 commands:
9 - git fetch --tags
10
11 - name: build
12 image: golang
13 commands:
14 - go build
15 - 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: kubernetes
3 name: default
4
5 steps:
6 - name: submodules
7 image: alpine/git
8 commands:
9 - git submodule init
10 - git submodule update --recursive --remote
11
12 - name: build
13 image: golang
14 commands:
15 - go build
16 - 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: kubernetes
3 name: default
4
5 clone:
6 disable: true
7
8 steps:
9 - name: clone
10 image: alpine/git
11 commands:
12 - git clone https://github.com/octocat/hello-world.git .
13 - git checkout $DRONE_COMMIT
14
15 - name: build
16 image: golang
17 commands:
18 - go build
19 - go test