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

**URL:** <https://drone.discourse.group/t/how-to-launch-a-build-deployment-without-knowing-the-build-number/11989>\
**Category:** Drone Support\
**Created:** [May 6, 2022, 9:12am UTC](https://drone.discourse.group/t/how-to-launch-a-build-deployment-without-knowing-the-build-number/11989 "2022-05-06T09:12:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilyavaiser](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/ilyavaiser/32/7596_2.png) [@ilyavaiser](https://drone.discourse.group/u/ilyavaiser)\
**Post date:** [May 6, 2022, 9:12am UTC](https://drone.discourse.group/t/how-to-launch-a-build-deployment-without-knowing-the-build-number/11989/1 "2022-05-06T09:12:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jimsheldon](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/jimsheldon/32/7760_2.png) [@jimsheldon](https://drone.discourse.group/u/jimsheldon)\
**Post date:** [May 10, 2022, 8:34pm UTC](https://drone.discourse.group/t/how-to-launch-a-build-deployment-without-knowing-the-build-number/11989/2 "2022-05-10T20:34:12Z")

</div>

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

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

```

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

---

<div class="post-metadata">

**Author:** ![ilyavaiser](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/ilyavaiser/32/7596_2.png) [@ilyavaiser](https://drone.discourse.group/u/ilyavaiser)\
**Post date:** [May 11, 2022, 1:02pm UTC](https://drone.discourse.group/t/how-to-launch-a-build-deployment-without-knowing-the-build-number/11989/3 "2022-05-11T13:02:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brad](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/brad/32/4172_2.png) [@brad](https://drone.discourse.group/u/brad)\
**Post date:** [May 11, 2022, 9:29pm UTC](https://drone.discourse.group/t/how-to-launch-a-build-deployment-without-knowing-the-build-number/11989/4 "2022-05-11T21:29:22Z")

</div>

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.

```auto
package main

import (
	"fmt"
	"time"

	"github.com/drone/drone-go/drone"
	"golang.org/x/oauth2"
)

const (
	token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
	host = "http://drone.company.com"
)

func main() {
	// create an http client with oauth authentication.
	config := new(oauth2.Config)
	auther := config.Client(
		oauth2.NoContext,
		&oauth2.Token{
			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 {
			log.Fatalln(err)
		}

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

		// else sleep
		time.Sleep(time.Minute)
	}

	// 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.
