File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ Paths accepted by `git sparse-checkout set`.
2020
2121Whether to pass ` --no-cone ` to ` git sparse-checkout ` so that the paths are considered to be a list of patterns.
2222
23+ #### ` skip_ssh_keyscan ` ('true' or 'false')
24+
25+ Whether to skip ssh-keyscan step. This will skip adding each ssh public key into the known-hosts file. Only use if ssh keys are already setup.
26+
2327## Example
2428
2529Below is an example for using sparse-checkout plugin.
Original file line number Diff line number Diff line change 1818 exit 1
1919fi
2020
21- echo " Scanning SSH keys for remote git repository"
22- [[ -d ~ /.ssh ]] || mkdir -p ~ /.ssh
23- ssh-keyscan " ${BUILDKITE_REPO_SSH_HOST} " >> ~ /.ssh/known_hosts
21+ SKIP_SSH_KEYSCAN_OPTION=" $( plugin_read_config SKIP_SSH_KEYSCAN " false" ) "
22+
23+ if [ " $SKIP_SSH_KEYSCAN_OPTION " = " false" ]; then
24+ echo " Scanning SSH keys for remote git repository"
25+ [[ -d ~ /.ssh ]] || mkdir -p ~ /.ssh
26+ ssh-keyscan " ${BUILDKITE_REPO_SSH_HOST} " >> ~ /.ssh/known_hosts
27+ else
28+ echo " Skipped SSH keyscan"
29+ fi
2430
2531echo " Creating sparse-checkout with paths: ${CHECKOUT_PATHS[*]} "
2632
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ configuration:
1010 no_cone :
1111 type : boolean
1212 default : false
13+ skip_ssh_keyscan :
14+ type : boolean
15+ default : false
1316 required :
1417 - paths
1518 additionalProperties : false
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bats
2+
3+ setup () {
4+ load " ${BATS_PLUGIN_PATH} /load.bash"
5+
6+ # Uncomment to enable stub debugging
7+ # export CURL_STUB_DEBUG=/dev/tty
8+
9+ # you can set variables common to all tests here
10+ export BUILDKITE_PLUGIN_SPARSE_CHECKOUT_PATHS=" default_path"
11+ export BUILDKITE_REPO_SSH_HOST=" default_host"
12+ export BUILDKITE_COMMIT=" dummy-commit-hash"
13+ }
14+
15+ @test " Skip ssh-keyscan when option provided" {
16+ export BUILDKITE_PLUGIN_SPARSE_CHECKOUT_SKIP_SSH_KEYSCAN=' true'
17+
18+ stub git " clean \* : echo 'git clean'"
19+ stub git " fetch --depth 1 origin \* : echo 'git fetch'"
20+ stub git " sparse-checkout set \* \* : echo 'git sparse-checkout'"
21+ stub git " checkout \* : echo 'checkout'"
22+
23+ run " $PWD " /hooks/checkout
24+
25+ assert_success
26+ assert_output --partial ' Skipped SSH keyscan'
27+
28+ unstub git
29+ }
30+
31+ @test " Run ssh-keyscan when no option provided" {
32+ unset BUILDKITE_PLUGIN_SPARSE_CHECKOUT_SKIP_SSH_KEYSCAN
33+
34+ stub ssh-keyscan " \* : echo 'keyscan'"
35+ stub git " clean \* : echo 'git clean'"
36+ stub git " fetch --depth 1 origin \* : echo 'git fetch'"
37+ stub git " sparse-checkout set \* \* : echo 'git sparse-checkout'"
38+ stub git " checkout \* : echo 'checkout'"
39+
40+ run " $PWD " /hooks/checkout
41+
42+ assert_success
43+ assert_output --partial ' Scanning SSH keys for remote git repository'
44+
45+ unstub git
46+ unstub ssh-keyscan
47+ }
You can’t perform that action at this time.
0 commit comments