Drone

Starlark context not have some detailed info

There is missing info from ctx variable, where I usually use when using drone.yml, some of them:

  • drone build info (link, build number, etc)
  • build start time

Can you add this info to ctx variable?

Thank you so much.

@bradrydzewski Can you list out latest ctx structure? because when I try to print(ctx) on pipeline and on drone starlark convert gives different result:
This is from pipeline:

echo "context"(
  build = "build"(
    action = "",
    after = "xxx",
    author_avatar = "xxx",
    author_email = "xxx",
    author_login = "xxx",
    author_name = "xxx",
    before = "xxx",
    branch = "develop",
    commit = "xxx",
    cron = "",
    environent = "",
    event = "push",
    link = "",
    message = "print ctx\n",
    params = {},
    ref = "refs/heads/develop",
    sender = "",
    source = "develop",
    source_repo = "",
    target = "develop",
    title = ""
  ),
  repo = "repo"(
    active = True,
    branch = "master",
    config = ".drone.star",
    git_http_url = "xxx",
    git_ssh_url = "xxx",
    ignore_forks = False,
    ignore_pull_requests = False,
    link = "xxx",
    name = "xxx",
    namespace = "xxx",
    private = True,
    protected = False,
    slug = "xxx",
    trusted = False,
    uid = "xxx",
    visibility = "private"
  )
)

and this is from drone starlark convert

"context"(
  build = "build"(
    branch = "master",
    commit = "",
    event = "push",
    message = "",
    ref = "refs/heads/master",
    source = "",
    target = ""
  ),
  repo = "repo"(
    name = "xxx",
    namespace = "",
    slug = ""
  )
)

That is why it gives error

2019/10/28 10:23:04 "build" struct has no .author_name attribute

when I try to

"BUILD_AUTHOR": "%s" % ctx.build.author_name,

The is expected. The starlark script is evaluated before the build is created, thus build number and build started are not available at that time.

Is there any way to get that information into the build? I want to convert to starlark because I need to script out a build for multiple architectures, but I’m using the drone build ID inside of one of my package scripts. Can I still use the Drone environment variables in the build somehow?


Edit: Ah, the environment variables are still set and can be accessed during the build.

This means in your build steps, which may be generated by starlark, you can echo $DRONE_BUILD_NUMBER and DRONE_BUILD_NUMBER will be resolved by the shell when it is executed by the Drone runner.

Sorry for the noise, but I’ll leave this here just in case anybody else needs it.