Using custom generated tags for Docker images

I have a script that generates a version string based on the current git commit and history. I want to use that version string for the docker images too. However, I can’t seem to figure out a way to run this script/program and then use its output version with the docker plugin.

For example, I’m trying something like:

- name: build
  image: golang:1.10.0-alpine
  commands:
    - [...]
    - export VERSION=$(git-buildnumber)

- name: push
  image: plugins/gcr
  settings:
    registry: gcr.io
    repo: ${DRONE_REPO_NAME}
    tags: "${VERSION}"

I know that environment variables are filled in before any steps run, so I can understand why this doesn’t work. Then, how can I possibly use a tag name generated at run-time with the docker plugin?

The reason this example does not work is because it is not possible at the unix level. One cannot create an environment variable in one process, and read that environment variable in a sibling process. We can reproduce the same results with these shell commands:

$ cat <<EOF > foo.sh
export FOO=bar
EOF
$ cat <<EOF > bar.sh
echo $FOO
EOF
$ sh foo.sh
$ sh bar.sh

$ 

If you need to share data between sibling processes (pipeline steps) you need to share this information by writing to and reading from disk. The docker plugin will automatically read tags from a .tags file, which means you can do this:

  - name: build
    image: golang:1.10.0-alpine
    commands:
      - [...]
-     - export VERSION=$(git-buildnumber)
+     - echo -n $(git-buildnumber) > .tags

  - name: push
    image: plugins/gcr
    settings:
      registry: gcr.io
      repo: ${DRONE_REPO_NAME}
-     tags: "${VERSION}"

Great - thanks so much. This .tags file should be documented, though, as it’s nowhere to be found here: http://plugins.drone.io/drone-plugins/drone-docker/

There are a lot of things that should be documented. If you find one of them, sending a pull request is much appreciated :slight_smile:

I’d gladly do that, but I can’t seem to figure out where the docs live. drone/docs doesn’t seem like it, and the plugin repo itself has no docs. Perhaps the pages should link to their source files on GitHub, to make it trivial to find what page to contribute to.

drone/docs is live, but this represents the drone core documentation. Plugins are completely separate entities and are documented at plugins.drone.io. The source is found here github.com/drone/drone-plugin-index