How to launch a build deployment without knowing the build number?

I need to be able to deploy separate dev branches to different test servers. This is currently working in gitlab-ci, I’m trying to figure out how I can move this to Drone.

For example, I would like to run build from Gitalb via the Drone api, and then, after building it, do a promote of this build. But, do I need to know build number?

And how do I get it, for example, the last build number for a branch?

You could find the most recent build number either with the CLI or the API, here is an example with the CLI:

$ drone build ls --branch master --limit 1 --format "{{ .Number }}" drone/go-scm

Edit: sorry I read your post too quickly and didn’t realize you are using GitLab, is my CLI example helpful?

I can do this, but will the build be ready for deployment at this point?

In other words, I start the build, then I need to wait until it completes. Then I need to understand if it completes successfully. And then make a deployment.

I have no idea yet how exactly I can do this.

Drone provides a fully features API, CLI and SDK that you can use to write custom code or shell scripts. Below is an example of how you could use the SDK to achieve your goal. You could also write a custom shell script using the CLI which is what Jim was proposing.

package main

import (


const (
	token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
	host  = ""

func main() {
	// create an http client with oauth authentication.
	config := new(oauth2.Config)
	auther := config.Client(
			AccessToken: token,

	// create the drone client with authenticator
	client := drone.NewClient(host, auther)

	var build *drone.Build
	var err error

	// wait for build to complete
	for {
		build, err = client.BuildLast("bradrydzewski", "hello-world", "master")
		if err != nil {

		// if finished date is > 0 we know build is complete
		if build.Finished != 0 {

		// else sleep

	// promote the build
	promoted, err := client.Promote("bradrydzewski", "hello-world", build.Number, "production", nil)
	log.Println(promoted, err)

Note that the above code is psuedo code and may need some minor adjustments in order to compile, but hopefully you can use as a starting point.