cirrus-ci-docs icon indicating copy to clipboard operation
cirrus-ci-docs copied to clipboard

Environment variable override for manually created builds

Open Jackenmen opened this issue 2 years ago • 3 comments

Expected Behavior

I expected that triggering a manual build with "override build configuration" passed would cause it to append/only override the part of the build configuration that was passed to, i.e. when passing an env var, I expected it to only override that single env var no matter if I'm using .cirrus.star or .cirrus.yaml.

Build configuration

Example 1:

  • .cirrus.yml
example_task:
  container:
    image: ubuntu:latest
  script: echo "${CUSTOM_VAR:-default value}"

Example 2:

  • .cirrus.star
load("github.com/cirrus-modules/helpers", "container", "script", "task")


def main(ctx):
    return [
        task("example", container("ubuntu:latest"), {}, [script('echo "${CUSTOM_VAR:-default value}"')])
    ]

Real Behavior

The override only worked when using .cirrus.star - nothing from .cirrus.yaml is part of the manually triggered build.

Example tasks:

  • using .cirrus.star (properly working):
    • on push: https://cirrus-ci.com/task/4793416981676032
    • manual: https://cirrus-ci.com/task/5384766030610432
  • using .cirrus.yml (not working correctly):
    • on push: https://cirrus-ci.com/task/5343097331646464
    • manual: https://cirrus-ci.com/build/6549067172937728

Related Info

This is a (tick one of the following):

  • [ ] Website issue
    • Link to page:
  • [x] Task issue
    • OS: any
    • Task name: example
    • Script/cache name (if applies): N/A

Jackenmen avatar Jul 20 '22 21:07 Jackenmen

I was unsure if this isn't perhaps a feature request but since it works with .cirrus.star, it might be that it's just a bug.

Jackenmen avatar Jul 20 '22 21:07 Jackenmen

The configOverride GraphQL field overrides the whole YAML configuration, not just a part of it.

The Starlark configuration is left untouched since the Starlark option was introduced relatively recently to the createBuild() GraphQL mutation. Perhaps we need to add a starlarkConfigOverride field too (/cc @fkorotkov).

Regarding the ability to partially overwrite a configuration (like env), you can use Starlark for that. Note that the resulting YAML configuration from .yml/.yaml and Starlark are merged together, so the fields that are not overwritten by Starlark will remain in the resulting map, e.g.:

env:
  COLOR: red
  WARMTH: hot

# Override from Starlark
env:
  COLOR: yellow

...will result in:

env:
  COLOR: yellow
  WARMTH: hot

edigaryev avatar Jul 22 '22 13:07 edigaryev

Regarding the ability to partially overwrite a configuration (like env), you can use Starlark for that. Note that the resulting YAML configuration from .yml/.yaml and Starlark are merged together, so the fields that are not overwritten by Starlark will remain in the resulting map, e.g.:

I want to partially overwrite a configuration from the manual build UI so the ability to override from Starlark doesn't help here: image

What I want is to be able to use both .cirrus.yaml and .cirrus.star files and be able to partially overwrite a configuration (or just have any way at all to specify some custom parameters for the build) from the manual build UI. I suppose that this makes it a feature request then since it seems that the current UI has a different purpose.

Jackenmen avatar Jul 22 '22 13:07 Jackenmen