Skip to content

Instantly share code, notes, and snippets.

@iflamed
Last active October 11, 2021 03:25
Show Gist options
  • Save iflamed/2d5aced9148714dcebe0c4918bcc917f to your computer and use it in GitHub Desktop.
Save iflamed/2d5aced9148714dcebe0c4918bcc917f to your computer and use it in GitHub Desktop.
Drone CI: git clone with ssh in the clone step
---
kind: pipeline
type: docker
name: default
clone:
disable: true
steps:
- name: clone
image: alpine/git
pull: if-not-exists
environment:
SSH_KEY:
from_secret: SSH_KEY
SSH_HOST:
from_secret: SSH_HOST
SSH_PORT:
from_secret: SSH_PORT
commands:
- mkdir $HOME/.ssh && echo "$SSH_KEY" > $HOME/.ssh/id_rsa && chmod 600 $HOME/.ssh/id_rsa
- |
[[ -n "$${SSH_PORT}" ]] && [[ -n "$${SSH_HOST}" ]] && ssh-keyscan -p $${SSH_PORT} $${SSH_HOST} >> $HOME/.ssh/known_hosts
- |
[[ -z "$${SSH_PORT}" ]] && [[ -n "$${SSH_HOST}" ]] && ssh-keyscan $${SSH_HOST} >> $HOME/.ssh/known_hosts
- git clone ${DRONE_GIT_SSH_URL} .
- git checkout ${DRONE_COMMIT_BRANCH}
- name: greeting
image: alpine
pull: if-not-exists
commands:
- echo "hello, world"
- ls -ahl
- pwd
@wangyuhuiever
Copy link

如果要放到git上的确实会不安全,我这里没放,都是直接在本地编辑的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment