drone


原文链接: drone
  1. DRONE 变量在 github.com/cncd/pipeline/pipeline/frontend/metadata.go 中定义
    params := map[string]string{
    "CI": "drone",
    "DRONE": "true",
    "DRONE_ARCH": "linux/amd64",
    "DRONE_REPO": m.Repo.Name,
    "DRONE_REPO_SCM": "git",
    "DRONE_REPO_OWNER": owner,
    "DRONE_REPO_NAME": name,
    "DRONE_REPO_LINK": m.Repo.Link,
    "DRONE_REPO_BRANCH": m.Curr.Commit.Branch,
    "DRONE_REPO_PRIVATE": fmt.Sprintf("%v", m.Repo.Private),
    "DRONE_REPO_TRUSTED": "false", // TODO should this be added?
    "DRONE_REMOTE_URL": m.Repo.Remote,
    "DRONE_COMMIT_SHA": m.Curr.Commit.Sha,
    "DRONE_COMMIT_REF": m.Curr.Commit.Ref,
    "DRONE_COMMIT_REFSPEC": m.Curr.Commit.Refspec,
    "DRONE_COMMIT_BRANCH": m.Curr.Commit.Branch,
    "DRONE_COMMIT_LINK": m.Curr.Link,
    "DRONE_COMMIT_MESSAGE": m.Curr.Commit.Message,
    "DRONE_COMMIT_AUTHOR": m.Curr.Commit.Author.Name,
    "DRONE_COMMIT_AUTHOR_EMAIL": m.Curr.Commit.Author.Email,
    "DRONE_COMMIT_AUTHOR_AVATAR": m.Curr.Commit.Author.Avatar,
    "DRONE_BUILD_NUMBER": fmt.Sprintf("%d", m.Curr.Number),
    "DRONE_PARENT_BUILD_NUMBER": fmt.Sprintf("%d", m.Curr.Parent),
    "DRONE_BUILD_EVENT": m.Curr.Event,
    "DRONE_BUILD_LINK": fmt.Sprintf("%s/%s/%d", m.Sys.Link, m.Repo.Name, m.Curr.Number),
    "DRONE_BUILD_CREATED": fmt.Sprintf("%d", m.Curr.Created),
    "DRONE_BUILD_STARTED": fmt.Sprintf("%d", m.Curr.Started),
    "DRONE_BUILD_FINISHED": fmt.Sprintf("%d", m.Curr.Finished),
    "DRONE_JOB_NUMBER": fmt.Sprintf("%d", m.Job.Number),
    "DRONE_JOB_STARTED": fmt.Sprintf("%d", m.Curr.Started), // ISSUE: no job started
    "DRONE_BRANCH": m.Curr.Commit.Branch,
    "DRONE_COMMIT": m.Curr.Commit.Sha,
    "DRONE_VERSION": m.Sys.Version,
    "DRONE_DEPLOY_TO": m.Curr.Target,
    "DRONE_PREV_BUILD_STATUS": m.Prev.Status,
    "DRONE_PREV_BUILD_NUMBER": fmt.Sprintf("%v", m.Prev.Number),
    "DRONE_PREV_COMMIT_SHA": m.Prev.Commit.Sha,
    }

DRONE_BRANCH=master
DRONE_REPO_OWNER=linyibr
DRONE_REPO_NAME=zhongxinguoan
DRONE_REMOTE_URL=http://git.chinaoss.com/linyibr/zhongxinguoan.git
DRONE_WORKSPACE=/go/src/git.chinaoss.com/linyibr/zhongxinguoan
DRONE_REPO=linyibr/zhongxinguoan

LOCAL_VOLUME=/root/docker/linyibr/zhongzheng
DRONE_NETRC_MACHINE=git.chinaoss.com
DRONE_COMMIT_AUTHOR_AVATAR=https://secure.gravatar.com/avatar/b2d169c1392c919507f0a579e42efb6a
DRONE_JOB_FINISHED=1495533194
CI_PREV_COMMIT_AUTHOR_NAME=root
CI=drone
HOSTNAME=0dab316e446e
CI_BUILD_NUMBER=16
DRONE_COMMIT_AUTHOR=root
DRONE_REPO_LINK=http://git.chinaoss.com/linyibr/zhongxinguoan
CI_BUILD_STARTED=1495533193
CI_PREV_COMMIT_AUTHOR_AVATAR=https://secure.gravatar.com/avatar/b2d169c1392c919507f0a579e42efb6a
CI_SYSTEM_LINK=http://drone.linyibr.com
CI_BUILD_LINK=http://git.chinaoss.com/linyibr/zhongxinguoan/compare/bf6e6c8133e99bf5eac10b1e15d327f4c667099f...3f267ce6c06f66bad965d83fc67f22bd535c7041
CI_WORKSPACE=/go/src/git.chinaoss.com/linyibr/zhongxinguoan
DRONE_PREV_BUILD_NUMBER=15
SHLVL=2
HOME=/root
DRONE_COMMIT_BRANCH=master
DRONE_REPO_PRIVATE=true
DRONE_REPO_SCM=git
CI_PREV_COMMIT_AUTHOR=root
DRONE_BUILD_STATUS=success
CI_PREV_COMMIT_BRANCH=master
CI_JOB_NUMBER=1
CI_JOB_STARTED=1495533193
CI_BUILD_EVENT=push
DRONE_ARCH=linux/amd64
CI_REPO_NAME=linyibr/zhongxinguoan
CI_BUILD_CREATED=1495533193
CI_COMMIT_SHA=3f267ce6c06f66bad965d83fc67f22bd535c7041
CI_COMMIT_REF=refs/heads/master
DRONE_PREV_COMMIT_SHA=bf6e6c8133e99bf5eac10b1e15d327f4c667099f
CI_PREV_BUILD_STATUS=success
DRONE_COMMIT_MESSAGE=drone

DRONE_REPO_BRANCH=master
CI_BUILD_FINISHED=1495533194
DRONE_JOB_STATUS=success
CI_REPO=linyibr/zhongxinguoan
CI_PREV_COMMIT_MESSAGE=drone

CI_COMMIT_AUTHOR_NAME=root
CI_NETRC_MACHINE=git.chinaoss.com
DRONE=true
CI_COMMIT_AUTHOR_AVATAR=https://secure.gravatar.com/avatar/b2d169c1392c919507f0a579e42efb6a
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DRONE_BUILD_NUMBER=16
DRONE_BUILD_STARTED=1495533193
CI_JOB_FINISHED=1495533194
DRONE_BUILD_LINK=http://drone.linyibr.com/linyibr/zhongxinguoan/16
CI_COMMIT_AUTHOR=root
CI_REPO_LINK=http://git.chinaoss.com/linyibr/zhongxinguoan
CI_PREV_BUILD_STARTED=1495533163
CI_PREV_BUILD_NUMBER=15
CI_PREV_BUILD_LINK=http://git.chinaoss.com/linyibr/zhongxinguoan/compare/3db5a4b510e56c3c35f73c3a6b375ceb4b9f2186...bf6e6c8133e99bf5eac10b1e15d327f4c667099f
CI_COMMIT_BRANCH=master
CI_REPO_REMOTE=http://git.chinaoss.com/linyibr/zhongxinguoan.git
SHELL=/bin/sh
DRONE_COMMIT=3f267ce6c06f66bad965d83fc67f22bd535c7041
CI_SYSTEM_ARCH=linux/amd64
CI_REPO_PRIVATE=true
DRONE_JOB_NUMBER=1
DRONE_BUILD_EVENT=push
DRONE_JOB_STARTED=1495533193
DRONE_BUILD_CREATED=1495533193
DRONE_COMMIT_SHA=3f267ce6c06f66bad965d83fc67f22bd535c7041

CI_SYSTEM_NAME=drone
CI_BUILD_STATUS=success
DRONE_COMMIT_REF=refs/heads/master
DRONE_PREV_BUILD_STATUS=success
CI_PREV_BUILD_EVENT=push
PWD=/go/src/git.chinaoss.com/linyibr/zhongxinguoan
DRONE_COMMIT_LINK=http://git.chinaoss.com/linyibr/zhongxinguoan/compare/bf6e6c8133e99bf5eac10b1e15d327f4c667099f...3f267ce6c06f66bad965d83fc67f22bd535c7041
CI_PREV_COMMIT_SHA=bf6e6c8133e99bf5eac10b1e15d327f4c667099f
DRONE_BUILD_FINISHED=1495533194
CI_PREV_BUILD_CREATED=1495533162
CI_PREV_COMMIT_REF=refs/heads/master
CI_COMMIT_MESSAGE=drone

CI_SYSTEM=drone
CI_JOB_STATUS=success
CI_PREV_BUILD_FINISHED=1495533167
CI_REMOTE_URL=http://git.chinaoss.com/linyibr/zhongxinguoan.git

#drone 0.6
$DRONE_REPO bianban/chirp
$DRONE_REPO_LINK http://git.linyibr.com/bianban/chirp

$DRONE_ARCH linux/amd64
$DRONE_REPO_OWNER bianban
$DRONE_REPO_NAME chirp
$DRONE_REPO_BRANCH master
$DRONE_REPO_PRIVATE true
$DRONE_REPO_TRUSTED
DRONE_REMOTE_URL http://git.linyibr.com/bianban/chirp.git
DRONE_COMMIT_SHA 6d4f6973c331ec946ec5844b6ab10b744439bb16
DRONE_COMMIT_REF refs/heads/master
DRONE_COMMIT_REFSPEC
DRONE_COMMIT_LINK http://git.linyibr.com/bianban/chirp/compare/cc53507e583b7c70b63a93c8e2945ee2a3afe6dd...6d4f6973c331ec946ec5844b6ab10b744439bb16
DRONE_COMMIT_BRANCH master
DRONE_COMMIT_MESSAGE
DRONE_REPO
DRONE_COMMIT_AUTHOR root
DRONE_COMMIT_AUTHOR_EMAIL
DRONE_COMMIT_AUTHOR_AVATAR https://secure.gravatar.com/avatar/b2d169c1392c919507f0a579e42efb6a
DRONE_BUILD_NUMBER 13
DRONE_BUILD_EVENT push
DRONE_BUILD_LINK http://drone.linyibr.com/bianban/chirp/13
DRONE_BUILD_CREATED 1494309580
DRONE_BUILD_STARTED 1494309581
DRONE_BUILD_FINISHED 1494309582
DRONE_JOB_NUMBER 1
DRONE_JOB_STARTED 1494309581
DRONE_BRANCH master
DRONE_COMMIT 6d4f6973c331ec946ec5844b6ab10b744439bb16
DRONE_VERSION
DRONE_DEPLOY_TO
DRONE_PREV_BUILD_STATUS failure
DRONE_PREV_BUILD_NUMBER 12
DRONE_PREV_COMMIT_SHA cc53507e583b7c70b63a93c8e2945ee2a3afe6dd

drone 0.5

Environment variables passed to your containers at runtime:
NAME DESC
CI=drone environment is drone
DRONE=true environment is drone
DRONE_ARCH environment architecture (linux/amd64)
DRONE_REPO repository full name yimeng/php-yimeng
DRONE_REPO_OWNER repository owner yimeng
DRONE_REPO_NAME repository name php-yimeng
DRONE_REPO_SCM repository scm (git)
${DRONE_REPO_LINK} repository link http://git.yimengapp.com/yimeng/php-yimeng
DRONE_REPO_AVATAR repository avatar http://git.yimengapp.com/avatars/2
DRONE_REPO_BRANCH repository default branch (master) master
DRONE_REPO_PRIVATE repository is private true
DRONE_REPO_TRUSTED repository is trusted true
DRONE_REMOTE_URL repository clone url
DRONE_COMMIT_SHA commit sha
DRONE_COMMIT_REF commit ref
DRONE_COMMIT_BRANCH commit branch
DRONE_COMMIT_LINK commit link in remote
DRONE_COMMIT_MESSAGE commit message
DRONE_COMMIT_AUTHOR commit author username
DRONE_COMMIT_AUTHOR_EMAIL commit author email address
DRONE_COMMIT_AUTHOR_AVATAR commit author avatar
DRONE_BUILD_NUMBER build number
DRONE_BUILD_EVENT build event (push, pull_request, tag)
DRONE_BUILD_STATUS build status (success, failure)
DRONE_BUILD_LINK build result link
DRONE_BUILD_CREATED build created unix timestamp
DRONE_BUILD_STARTED build started unix timestamp
DRONE_BUILD_FINISHED build finished unix timestamp
DRONE_PREV_BUILD_STATUS prior build status
DRONE_PREV_BUILD_NUMBER prior build number
DRONE_PREV_COMMIT_SHA prior build commit sha
DRONE_JOB_NUMBER job number
DRONE_JOB_STATUS job status
DRONE_JOB_EXIT_CODE job exit code
DRONE_JOB_STARTED job started
DRONE_JOB_FINISHED job finished
DRONE_YAML_SIGNED yaml is signed
DRONE_YAML_VERIFIED yaml is signed and verified
DRONE_BRANCH commit branch
DRONE_COMMIT commit sha
DRONE_TAG commit tag
DRONE_PULL_REQUEST pull request number
DRONE_DEPLOY_TO deployment target (ie production)
String Interpolation

Environment variables are interpolated in the yaml using the ${VARIABLE} syntax, before the yaml is parsed. This is an example yaml file before interpolating environment variable:

pipeline:

s3:

source: archive.tar.gz
target: archive_${DRONE_COMMIT}.tar.gz

Example after interpolating the environment variable:

pipeline:

s3:

source: archive.tar.gz
target: archive_74475490bbad029da60cc96f1b6e6ab68436cb50.tar.gz

String Operations

Environment variable interpolation supports emulated bash string operations:
OPERATION DESC
${param} parameter substitution
"${param}" parameter substitution with escaping
${param:pos} parameter substitution with substring
${param:pos:len} parameter substitution with substring
${param=default} parameter substitution with default
${param##prefix} parameter substitution with prefix removal
${param%%suffix} parameter substitution with suffix removal
${param/old/new} parameter substitution with find and replace

Example operation to shorten the git sha value:

${DRONE_COMMIT:0:8}

Example operation to remove the v from git tag value v1.0.0:

${DRONE_TAG##v}

启动 server

   --debug												start the server in debug mode [$DRONE_DEBUG]
   --server-addr ":8000"					server address [$DRONE_SERVER_ADDR]
   --server-cert									server ssl cert [$DRONE_SERVER_CERT]
   --server-key									  server ssl key [$DRONE_SERVER_KEY]
   --admin [--admin option --admin option]			list of admin users [$DRONE_ADMIN]
   --orgs [--orgs option --orgs option]				list of approved organizations [$DRONE_ORGS]
   --open												  open user registration [$DRONE_OPEN]
   --yaml ".drone.yml"						build configuraton file name [$DRONE_YAML]
   --cache-tty "15m0s"						cache duration [$DRONE_CACHE_TTY]
   --agent-secret									agent secret passcode [$DRONE_AGENT_SECRET, $DRONE_SECRET]
   --driver "sqlite3"						  database driver [$DRONE_DATABASE_DRIVER, $DATABASE_DRIVER]
   --datasource "drone.sqlite"		database driver configuration string [$DRONE_DATABASE_DATASOURCE, $DATABASE_CONFIG]
   --github												github driver is enabled [$DRONE_GITHUB]
   --github-server "https://github.com"				github server address [$DRONE_GITHUB_URL]
   --github-context "continuous-integration/drone"		github status context [$DRONE_GITHUB_CONTEXT]
   --github-client								github oauth2 client id [$DRONE_GITHUB_CLIENT]
   --github-secret								github oauth2 client secret [$DRONE_GITHUB_SECRET]
   --github-scope [--github-scope option --github-scope option]	github oauth scope [$DRONE_GITHUB_SCOPE]
   --github-git-username 					github machine user username [$DRONE_GITHUB_GIT_USERNAME]
   --github-git-password 					github machine user password [$DRONE_GITHUB_GIT_PASSWORD]
   --github-merge-ref						  github pull requests use merge ref [$DRONE_GITHUB_MERGE_REF]
   --github-private-mode					github is running in private mode [$DRONE_GITHUB_PRIVATE_MODE]
   --github-skip-verify						github skip ssl verification [$DRONE_GITHUB_SKIP_VERIFY]
   --gogs												  gogs driver is enabled [$DRONE_GOGS]
   --gogs-server "https://github.com"				gogs server address [$DRONE_GOGS_URL]
   --gogs-git-username						gogs service account username [$DRONE_GOGS_GIT_USERNAME]
   --gogs-git-password						gogs service account password [$DRONE_GOGS_GIT_PASSWORD]
   --gogs-private-mode						gogs private mode enabled [$DRONE_GOGS_PRIVATE_MODE]
   --gogs-skip-verify						  gogs skip ssl verification [$DRONE_GOGS_SKIP_VERIFY]
   --bitbucket										bitbucket driver is enabled [$DRONE_BITBUCKET]
   --bitbucket-client							bitbucket oauth2 client id [$DRONE_BITBUCKET_CLIENT]
   --bitbucket-secret							bitbucket oauth2 client secret [$DRONE_BITBUCKET_SECRET]
   --gitlab												gitlab driver is enabled [$DRONE_GITLAB]
   --gitlab-server "https://gitlab.com"				gitlab server address [$DRONE_GITLAB_URL]
   --gitlab-client								gitlab oauth2 client id [$DRONE_GITLAB_CLIENT]
   --gitlab-secret								gitlab oauth2 client secret [$DRONE_GITLAB_SECRET]
   --gitlab-git-username 					gitlab service account username [$DRONE_GITLAB_GIT_USERNAME]
   --gitlab-git-password 					gitlab service account password [$DRONE_GITLAB_GIT_PASSWORD]
   --gitlab-skip-verify						gitlab skip ssl verification [$DRONE_GITLAB_SKIP_VERIFY]
   --gitlab-private-mode					gitlab is running in private mode [$DRONE_GITLAB_PRIVATE_MODE]
   --stash												stash driver is enabled [$DRONE_STASH]
   --stash-server									stash server address [$DRONE_STASH_URL]
   --stash-consumer-key 					stash oauth1 consumer key [$DRONE_STASH_CONSUMER_KEY]
   --stash-consumer-rsa 					stash oauth1 private key file [$DRONE_STASH_CONSUMER_RSA]
   --stash-git-username 					stash service account username [$DRONE_STASH_GIT_USERNAME]
   --stash-git-password 					stash service account password [$DRONE_STASH_GIT_PASSWORD]
   --stash-skip-verify						stash skip ssl verification [$DRONE_STASH_SKIP_VERIFY]

对比:
https://en.wikipedia.org/wiki/Comparison_of_continuous_integration_software

drone 0.5 文档
drone 0.5 文档
drone demos

Documentation

install

  1. SQlite3
    apt-get install libsqlite3-dev
    yum install sqlite-devel
  2. drone 0.3
    wget downloads.drone.io/master/drone.deb & dpkg -i drone.deb
    Created symlink from /etc/systemd/system/multi-user.target.wants/drone.service to /lib/systemd/system/drone.service.
    wget downloads.drone.io/master/drone.rpm & yum localinstall drone.rpm

config

drone --server=192.168.1.106:8000 --token=16239bb0e63719b6f133
curl -i 'https://api.github.com/users/whatever?client_id=16239bb0e63719b6f133&client_secret=f854840a2217af573aaf9cbd7119d445e7ab8806'

运行drone0.5 server

  1. 通过drone 命令
    drone server --server-addr=":80" --github --github-client=16239bb0e63719b6f133 --github-secret=f854840a2217af573aaf9cbd7119d445e7ab8806 --agent-secret=16239bb0e63719b6f133 --open

export DRONE_SERVER=http://kbook.org
export DRONE_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiMTYyMzliYjBlNjM3MTliNmYxMzMiLCJ0eXBlIjoiYWdlbnQifQ.A4gUVyDDECZDhF429f0fqrZ0pLzL84Pg_iyK9Td8VKs
drone server -s http://kbook.org -t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXh0IjoiMTYyMzliYjBlNjM3MTliNmYxMzMiLCJ0eXBlIjoiYWdlbnQifQ.A4gUVyDDECZDhF429f0fqrZ0pLzL84Pg_iyK9Td8VKs

  1. 通过docker 运行

docker run -d
-e DRONE_GITHUB=true
-e DRONE_GITHUB_CLIENT=...
-e DRONE_GITHUB_SECRET=...
-e DRONE_SECRET=...
-e DRONE_OPEN=true
-e DRONE_ADMIN=...
-v /var/lib/drone:/var/lib/drone
-p 80:8000
--restart=always
--name=drone
drone/drone:0.5

docker run -d --restart=always --name=drone-server -p 80:8000 -v /var/lib/drone:/var/lib/drone -v /var/run/docker.sock:/var/run/docker.sock drone/drone:0.5

  1. dronerc
    docker run -d --restart=always --name=drone-server -p 80:8000 -v /var/lib/drone:/var/lib/drone -v /var/run/docker.sock:/var/run/docker.sock --env-file dronerc drone/drone
`