项目作者: appleboy

项目描述 :
php curl for drone plugin
高级语言: PHP
项目地址: git://github.com/appleboy/drone-php-curl.git
创建时间: 2017-06-30T14:25:37Z
项目社区:https://github.com/appleboy/drone-php-curl

开源协议:MIT License

下载


Example PHP Plugin

This provides a brief tutorial for creating a Drone webhook plugin, using simple php scripting, to make an http requests during the build pipeline. The below example demonstrates how we might configure a webhook plugin in the Yaml file:

  1. pipeline:
  2. webhook:
  3. image: foo/webhook
  4. url: http://foo.com
  5. method: post
  6. body: |
  7. hello world

Create a simple shell script that invokes curl using the Yaml configuration parameters, which are passed to the script as environment variables in uppercase and prefixed with PLUGIN_.

  1. <?php
  2. $method = getenv('PLUGIN_METHOD');
  3. $body = getenv('PLUGIN_BODY');
  4. $url = getenv('PLUGIN_URL');
  5. curl_setopt($ch, CURLOPT_URL, $url);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  7. if ($method === "post") {
  8. curl_setopt($ch, CURLOPT_POST, 1);
  9. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
  10. }
  11. $output = curl_exec($ch);
  12. curl_close($ch);
  13. echo $output;

Create a Dockerfile that adds your shell script to the image, and configures the image to execute your shell script as the main entrypoint.

  1. FROM laradock/workspace:1.8-71
  2. ADD curl.php /
  3. ENTRYPOINT ["php", "curl.php"]

Build and publish your plugin to the Docker registry. Once published your plugin can be shared with the broader Drone community.

  1. docker build -t foo/webhook .
  2. docker push foo/webhook

Execute your plugin locally from the command line to verify it is working:

  1. docker run --rm \
  2. -e PLUGIN_METHOD=post \
  3. -e PLUGIN_URL=http://foo.com \
  4. -e PLUGIN_BODY="hello world" \
  5. foo/webhook