Drone

Find environment for a given promote

How can I discover which Environment a given drone build promote was targeting?

I believe the variable name is DRONE_DEPLOY_TO

I’m not being clear. I’m trying to look backwards in time: via drone build info or drone build ls and find the environment the promote affected.

Attempts include:

$ drone build ls --format="{{ .Number }} {{ .Event }} {{ .Target }} {{ .DroneDeployTo }}\n" --branch=master $REPO
541 pull_request master 540 promote master 539 promote master 538 promote master ...

(which, interestingly does not print newlines in the output… small bug there I think)

$ drone build ls --format="{{ .Number }} {{ .Event }} {{ .Target }} {{ .DeployTo }}\n" --branch=master $REPO
541 pull_request master 540 promote master 539 promote master 538 promote master ...

(same small bug)

$ drone build ls --format="{{ .Number }} {{ .Event }} {{ .Target }}\n" --branch=master $REPO
541 pull_request master\n
540 promote master\n
539 promote master\n
538 promote master\n
537 promote master\n
...

(proves I don’t need the trailing \n)

A new line is automatically added, so you do not need to include \n in --format. When I run the command this is what I get:

$ drone build ls drone/drone --format="{{ .Number }} {{ .Event }} {{ .Target }}"
152 push master
151 tag 
150 push master
149 push master
148 pull_request master
147 push master
146 push master
145 pull_request master

Since I cannot reproduce any issues with the entries printing on the same line, I would recommend sending a patch if it is something you can reliably reproduce.

And I’ve lead you astray.

Issue 1:
via drone build info or drone build ls or similar, determine the environment a given promotion was directed towards.

Issue 2:
When you use drone build ls with an invalid format label, rather than producing an error, the rest of the template is eaten, and doesn’t work. Example:

$ drone build ls --format="{{ .Number }} {{ .tag_not_appearing_in_drone }} {{ .Target }}" ${REPO}
566 565 564 563 562 561 560 559 558 557 556 555 554 553 552 551 550 549 548 547 546 545 544 543 542

Thank you! Your answer Using the command line - where is the commit sha? gave me the hint I needed.

I was looking for {{ .Deploy }}