Substitution

Drone provides the ability to substitute repository and build metadata to facilitate dynamic pipeline configurations.

Example commit substitution:

pipeline:
  docker:
    image: plugins/docker
+   tags: "${DRONE_COMMIT_SHA}"

Example tag substitution:

pipeline:
  docker:
    image: plugins/docker
+   tags: "${DRONE_TAG}"

String Operations

Drone provides partial emulation for bash string operations. This can be used to manipulate string values prior to substitution.

Example variable substitution with substring:

pipeline:
  docker:
    image: plugins/docker
+   tags: "${DRONE_COMMIT_SHA:0:8}"

Example variable substitution strips v prefix from v1.0.0:

pipeline:
  docker:
    image: plugins/docker
+   tags: "${DRONE_TAG##v}"

Example variable substitution replaces / with -:

pipeline:
  docker:
    image: plugins/docker
+   tags: ${DRONE_BRANCH/\//-}

String Operations Reference

List of emulated string operations:

OPERATION DESC
${param} parameter substitution
${param,} parameter substitution with lowercase first char
${param,,} parameter substitution with lowercase
${param^} parameter substitution with uppercase first char
${param^^} parameter substitution with uppercase
${param:pos} parameter substitution with substring
${param:pos:len} parameter substitution with substring and length
${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

Environment Variables Reference

Please see the reference environment documentation for the complete list of Drone environment variables.

Questions?

We are always happy to help with questions you might have. Search our documentation or check out answers to common questions. You can also post questions or comments to our community forum.

Is there a mistake on this page? Please let us know or edit this page.