相信大家看完昨日的 [Day 11] Oops!Drone - 快速上手 ,並且練習完昨天的題目後,已經奠定了一些基礎,那麼我們今天來進階練習ㄧ下~
這些練習或許在未來的某一天,你們可以在某個地方應用的到!
第一個步驟就是定義主機的路徑。主機的路徑必須是絕對路徑。
volumes:
- name: mylog
host:
path: /tmp
而下一步驟是配置 Pipeline步驟,將命名的主機路徑掛載到容器中。容器的路徑也必須是絕對路徑。
steps:
- name: step_name
volumes:
- name: mylog
path: /tmp
以下是完整的示範
kind: pipeline
type: docker
name: backend
steps:
- name: practice make file
image: golang
commands:
- ls /tmp
- echo hello drone > /tmp/hi.txt
volumes:
- name: mylog
path: /tmp
- name: check volumes file
image: golang
commands:
- ls /tmp
volumes:
- name: mylog
path: /tmp
volumes:
- name: mylog
host:
path: /tmp
設定參數在官網有文件說明
以下是我把全部的參數直接印出來的做法
kind: pipeline
type: docker
name: backend
steps:
- name: show environment
image: golang
commands:
- echo "DRONE_BUILD_ACTION = ${DRONE_BUILD_ACTION}"
- echo "DRONE_BUILD_CREATED = ${DRONE_BUILD_CREATED}"
- echo "DRONE_BUILD_EVENT = ${DRONE_BUILD_EVENT}"
- echo "DRONE_BUILD_FINISHED = ${DRONE_BUILD_FINISHED}"
- echo "DRONE_BUILD_NUMBER = ${DRONE_BUILD_NUMBER}"
- echo "DRONE_BUILD_PARENT = ${DRONE_BUILD_PARENT}"
- echo "DRONE_BUILD_STARTED = ${DRONE_BUILD_STARTED}"
- echo "DRONE_BUILD_STATUS = ${DRONE_BUILD_STATUS}"
- echo "DRONE_COMMIT = ${DRONE_COMMIT}"
- echo "DRONE_COMMIT_AFTER = ${DRONE_COMMIT_AFTER}"
- echo "DRONE_COMMIT_AUTHOR = ${DRONE_COMMIT_AUTHOR}"
- echo "DRONE_COMMIT_AUTHOR_AVATAR = ${DRONE_COMMIT_AUTHOR_AVATAR}"
- echo "DRONE_COMMIT_AUTHOR_EMAIL = ${DRONE_COMMIT_AUTHOR_EMAIL}"
- echo "DRONE_COMMIT_AUTHOR_NAME = ${DRONE_COMMIT_AUTHOR_NAME}"
- echo "DRONE_COMMIT_BEFORE = ${DRONE_COMMIT_BEFORE}"
- echo "DRONE_COMMIT_BRANCH = ${DRONE_COMMIT_BRANCH}"
- echo "DRONE_COMMIT_LINK = ${DRONE_COMMIT_LINK}"
- echo "DRONE_COMMIT_MESSAGE = ${DRONE_COMMIT_MESSAGE}"
- echo "DRONE_COMMIT_REF = ${DRONE_COMMIT_REF}"
- echo "DRONE_COMMIT_SHA = ${DRONE_COMMIT_SHA}"
- echo "DRONE_DEPLOY_TO = ${DRONE_DEPLOY_TO}"
- echo "DRONE_FAILED_STAGES = ${DRONE_FAILED_STAGES}"
- echo "DRONE_FAILED_STEPS = ${DRONE_FAILED_STEPS}"
- echo "DRONE_GIT_HTTP_URL = ${DRONE_GIT_HTTP_URL}"
- echo "DRONE_GIT_SSH_URL = ${DRONE_GIT_SSH_URL}"
- echo "DRONE_PULL_REQUEST = ${DRONE_PULL_REQUEST}"
- echo "DRONE_REMOTE_URL = ${DRONE_REMOTE_URL}"
- echo "DRONE_REPO = ${DRONE_REPO}"
- echo "DRONE_REPO_BRANCH = ${DRONE_REPO_BRANCH}"
- echo "DRONE_REPO_LINK = ${DRONE_REPO_LINK}"
- echo "DRONE_REPO_NAME = ${DRONE_REPO_NAME}"
- echo "DRONE_REPO_NAMESPACE = ${DRONE_REPO_NAMESPACE}"
- echo "DRONE_REPO_OWNER = ${DRONE_REPO_OWNER}"
- echo "DRONE_REPO_PRIVATE = ${DRONE_REPO_PRIVATE}"
- echo "DRONE_REPO_SCM = ${DRONE_REPO_SCM}"
- echo "DRONE_REPO_VISIBILITY = ${DRONE_REPO_VISIBILITY}"
- echo "DRONE_SEMVER = ${DRONE_SEMVER}"
- echo "DRONE_SEMVER_BUILD = {DRONE_SEMVER_BUILD}"
- echo "DRONE_SEMVER_ERROR = ${DRONE_SEMVER_ERROR}"
- echo "DRONE_SEMVER_MAJOR = ${DRONE_SEMVER_MAJOR}"
- echo "DRONE_SEMVER_MINOR = ${DRONE_SEMVER_MINOR}"
- echo "DRONE_SEMVER_PATCH = ${DRONE_SEMVER_PATCH}"
- echo "DRONE_SEMVER_PRERELEASE = ${DRONE_SEMVER_PRERELEASE}"
- echo "DRONE_SEMVER_SHORT = ${DRONE_SEMVER_SHORT}"
- echo "DRONE_SOURCE_BRANCH = ${DRONE_SOURCE_BRANCH}"
- echo "DRONE_STAGE_ARCH = ${DRONE_STAGE_ARCH}"
- echo "DRONE_STAGE_DEPENDS_ON = ${DRONE_STAGE_DEPENDS_ON}"
- echo "DRONE_STAGE_FINISHED = ${DRONE_STAGE_FINISHED}"
- echo "DRONE_STAGE_KIND = ${DRONE_STAGE_KIND}"
- echo "DRONE_STAGE_MACHINE = ${DRONE_STAGE_MACHINE}"
- echo "DRONE_STAGE_NAME = ${DRONE_STAGE_NAME}"
- echo "DRONE_STAGE_NUMBER = ${DRONE_STAGE_NUMBER}"
- echo "DRONE_STAGE_OS = ${DRONE_STAGE_OS}"
- echo "DRONE_STAGE_STARTED = ${DRONE_STAGE_STARTED}"
- echo "DRONE_STAGE_STATUS = ${DRONE_STAGE_STATUS}"
- echo "DRONE_STAGE_TYPE = ${DRONE_STAGE_TYPE}"
- echo "DRONE_STAGE_VARIANT = ${DRONE_STAGE_VARIANT}"
- echo "DRONE_STEP_NAME = ${DRONE_STEP_NAME}"
- echo "DRONE_STEP_NUMBER = ${DRONE_STEP_NUMBER}"
- echo "DRONE_SYSTEM_HOST = ${DRONE_SYSTEM_HOST}"
- echo "DRONE_SYSTEM_HOSTNAME = ${DRONE_SYSTEM_HOSTNAME}"
- echo "DRONE_SYSTEM_PROTO = ${DRONE_SYSTEM_PROTO}"
- echo "DRONE_SYSTEM_VERSION = ${DRONE_SYSTEM_VERSION}"
- echo "DRONE_TAG = ${DRONE_TAG}"
- echo "DRONE_TARGET_BRANCH = ${DRONE_TARGET_BRANCH}"
kind: pipeline
type: docker
name: pipeline-01
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-01
---
kind: pipeline
type: docker
name: pipeline-02
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-02
---
kind: pipeline
type: docker
name: pipeline-03
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-03
kind: pipeline
type: docker
name: pipeline-01
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-01
---
kind: pipeline
type: docker
name: pipeline-02
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-02
depends_on:
- pipeline-01
---
kind: pipeline
type: docker
name: pipeline-03
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-03
depends_on:
- pipeline-02
kind: pipeline
type: docker
name: pipeline-01
clone:
disable: true
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-01
---
kind: pipeline
type: docker
name: pipeline-02
clone:
disable: true
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-02
depends_on:
- pipeline-01
---
kind: pipeline
type: docker
name: pipeline-03
clone:
disable: true
steps:
- name: practice
image: golang
commands:
- echo hello drone pipeline-03
depends_on:
- pipeline-02
如果要允許某個Step失敗而不使整個Pipeline失敗的話,可以在你需要允許可接受失敗的Step上面加上此設定。
kind: pipeline
type: docker
name: pipeline-01
clone:
disable: true
steps:
- name: steps 01
image: golang
failure: ignore
commands:
- echo hello drone steps 01
- ls abcdefg
- name: steps 02
image: golang
commands:
- echo hello drone steps 02
- name: steps 03
image: golang
commands:
- echo hello drone steps 03
效果就會如圖所示!
有些 Environment 可能不是如你預期的!
有些 Environment 可能是空值!
所以大家務必先行run看看,在你寫的 Pipeline內 Environment是否真的如你預期的取得,再導入到CI/CD流程內唷!
這兩日的練習相信大家對Drone的CI/CD設定已經有更深的了解,希望大家未來可以運用到往後的CI/CD的戰場上囉!