Tag variable in Yaml not working

Hi-
When i use $$TAG to tag the docker image im seeing this error $$TAG is not a valid repository/tag.
I believe $$TAG is used to fetch the git tag name. why wouldn’t it work?

The format have been changed with 0.5, please take a look at http://readme.drone.io/0.5/usage/environment-reference/#string-interpolation

Here is what im trying

pipeline:
  build:
    image: library/openjdk:8-jdk
    commands:
      - ./gradlew clean final
  docker:
   image: plugins/docker
   username: $DOCKER_USERNAME
   password: $DCOKER_PASSWORD
   email: $DOCKER_EMAIL
   registry: registry
   repo: repo
   tag: ${DRONE_TAG}
   environment:
     - DOCKER_LAUNCH_DEBUG=true
   when:
     branch: master
     event: push
     status: success

The first step builds and tags the git repo. In the next step im trying to push the docker image with the same tag created before
I have also tried $$TAG, but none of them worked. What im missing?

The first issue is that the git tag is not available for push events, because push events are for commits. The tag is only available for tag events, which is created when you create or push a tag in GitHub

pipeline:
  docker:
    image: plugins/docker
    tag: ${DRONE_TAG}
    when:
     branch: master
-    event: push
+    event: tag

The first step builds and tags the git repo

The tag variable comes from the GitHub tag hook and is interpolated into the yaml before it is parsed and before the build is executed. Tagging the repository during the build will not have any impact because the yaml has already been parsed.


The second issue is that secrets are not interpolated in the yaml and are instead provided to the image as environment variables. So the following syntax will not work.

pipeline:
  docker:
    image: plugins/docker
-     username: $DOCKER_USERNAME
-     password: $DCOKER_PASSWORD

I would highly recommend reading the 0.5 secret documentation considering secrets have significantly changed in 0.5. http://readme.drone.io/0.5/

This is what is happening…
I made the recommended changes
The build step automatically creates a tag in git repo, the docker publish step is not listening to the event as a part of this build, but rather after the build completes a separate drone build is kicked off and the docker is listening to the tag during the second build. Shouldn’t the docker event:tag be triggered during the first build???

shouldn’t the docker event:tag be triggered during the first build

nope

after the build completes a separate drone build is kicked off

exactly, this is the expected behavior. When you create a new tag and push that to github, github sends a new hook to drone, launching a new build.

Thanks!! Now it makes sense. Is there a way to trigger master build only one time. With the following im able to trigger the master only once but push build doesn’t work, it works if i specify the branch name, but is there a generic way that my push by default builds all the branches except master

pipeline:
  build:
    image: library/openjdk:8-jdk
    commands:
      - ./gradlew clean build
    when:
      event: [push, pull_request]
      branch: "!master"
  tag:
    image: library/openjdk:8-jdk
    commands:
      - ./gradlew clean build
    when:
      event: tag
  master:
    image: library/openjdk:8-jdk
    commands:
      - ./gradlew clean final 
    when:
      branch: master

I have gone through the docs, but cant find a way.

Is there a way to trigger master build only one time. With the following im able to trigger the master only once but push build doesn’t work

I’m sorry, I do not quite understand this question.

I can tell you the following syntax is incorrect and needs adjusting.

    when:
      event: [push, pull_request]
-     branch: "!master"
+     branch:
+       exclude: master

you can see examples at the following link
http://readme.drone.io/0.5/usage/conditional-build-steps/

also I think perhaps these additional question should be asked in a separate thread, since the original question about tags has been answered.