Build variable not available in yml template?

According new feature template https://docs.drone.io/template/yaml/, I defined a yml template include build variables

  - name: notice
    image: lizheming/drone-wechat
    settings:
      title: "{%if success %}😊{% else %}😭{% endif %} #{{.build.number}} {{.repo.name}} ${DRONE_DEPLOY_TO}"

with failed error

function "build" not defined

Before I use template, use {{build.number}} works fine, how to translate this into yml template?

The template is evaluated before the build is created, and before the build number is auto-incremented. This means you cannot use {{build.number}} in your template because it is not yet available. You can find a list of available fields at https://docs.drone.io/template/variables/

If build not available in template, there should be a way pass build varibles from .drone.yml to template,otherwise,we will never use build varibles with template or we can use build varibles but never use template, and we can’t use template and multi pipelines together…that seems not design logical

If build not available in template

{{ .build }} variables are supported, however, {{ .build.number }} is not a supported template variable. If you are interested in learning more about how it works you can audit the code here https://github.com/harness/drone/blob/master/plugin/converter/template.go#L96

{{ .repo.name }} also not work?

when I remove build.number variable, got another error

executing "welcome.yaml" at <.repo.name>: can't evaluate field name in type interface {}

Is there misunderstandings using variable in yaml template?

1 Like