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?
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.
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 (
"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.