Skip to content

Drone conversion extension to include/exclude pipelines and pipeline steps based on paths changed

License

Notifications You must be signed in to change notification settings

grafana/drone-convert-pathschanged

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Build Status Docker Pulls

A Drone conversion extension to include/exclude pipelines and steps based on paths changed.

Please note this project requires Drone server version 1.4 or higher.

Installation

Github

  1. Create a github token via https://github.com/settings/tokens with the scope ofrepo (see issue 13 for background).

  2. Create a shared secret:

$ openssl rand -hex 16
bea26a2221fd8090ea38720fc445eca6
  1. Download and run the plugin:
$ docker run -d \
  --publish=3000:3000 \
  --env=DRONE_DEBUG=true \
  --env=DRONE_SECRET=bea26a2221fd8090ea38720fc445eca6 \
  --env=TOKEN=9e6eij3ckzvpe9mrhnqcis6zf8dhopmm46e3pi96 \
  --env=PROVIDER=github \
  --restart=always \
  --name=converter meltwater/drone-convert-pathschanged
  1. Update your Drone server configuration to include the plugin address and the shared secret.
DRONE_CONVERT_PLUGIN_ENDPOINT=http://1.2.3.4:3000
DRONE_CONVERT_PLUGIN_SECRET=bea26a2221fd8090ea38720fc445eca6

Bitbucket Server

Bitbucket Server support is currently considered experimental

  1. Create a BitBucket access token via https://your-bitbucket-address/plugins/servlet/access-tokens/manage with read-only rights

  2. Create a shared secret:

$ openssl rand -hex 16
bea26a2221fd8090ea38720fc445eca6
  1. Download and run the plugin:
$ docker run -d \
  --publish=3000:3000 \
  --env=DRONE_DEBUG=true \
  --env=DRONE_SECRET=bea26a2221fd8090ea38720fc445eca6 \
  --env=TOKEN=9e6eij3ckzvpe9mrhnqcis6zf8dhopmm46e3pi96 \
  --env=PROVIDER=bitbucket-server \
  --restart=always \
  --name=converter meltwater/drone-convert-pathschanged
  1. Update your Drone server configuration to include the plugin address and the shared secret.
DRONE_CONVERT_PLUGIN_ENDPOINT=http://1.2.3.4:3000
DRONE_CONVERT_PLUGIN_SECRET=bea26a2221fd8090ea38720fc445eca6

Examples

This extension uses doublestar for matching paths changed in your commit range, refer to their documentation for all supported patterns.

include

Only run a pipeline when README.md is changed:

---
kind: pipeline
name: readme

trigger:
  paths:
    include:
    - README.md

steps:
- name: message
  image: busybox
  commands:
  - echo "README.md was changed”

Only run a pipeline step when README.md is changed:

---
kind: pipeline
name: readme

steps:
- name: message
  image: busybox
  commands:
  - echo "README.md was changed”
  when:
    paths:
      include:
      - README.md

include and exclude

Run a pipeline step when .yml files are changed in the root, except for .drone.yml:

---
kind: pipeline
name: yaml

steps:
- name: message
  image: busybox
  commands:
  - echo "A .yml file in the root of the repo other than .drone.yml was changed"
  when:
    paths:
      include:
      - "*.yml"
      exclude:
      - .drone.yml

depends_on

When using depends_on in a pipeline step, ensure the paths rules match, otherwise your steps may run out of order.

Only run two steps when README.md is changed, one after the other:

---
kind: pipeline
name: depends_on

steps:
- name: message
  image: busybox
  commands:
  - echo "README.md was changed”
  when:
    paths:
      include:
      - README.md

- name: depends_on_message
  depends_on:
  - message
  image: busybox
  commands:
  - echo "This step runs after the message step"
  when:
    paths:
      include:
      - README.md

Known issues

YAML anchors

There is a problem in the YAML library where ordering matters during unmarshaling, see meltwater#18

This syntax will fail:

anchor: &anchor
  image: busybox
  settings:
    foo: bar

- name: test
  <<: *anchor
  when:
    event: push
    branch: master

But this will succeed:

anchor: &anchor
  image: busybox
  settings:
    foo: bar

- <<: *anchor 
  name: test
  when:
    event: push
    branch: master

About

Drone conversion extension to include/exclude pipelines and pipeline steps based on paths changed

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.5%
  • Shell 0.5%