Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditional environment? #15

Closed
automaticgiant opened this issue Dec 11, 2017 · 4 comments
Closed

conditional environment? #15

automaticgiant opened this issue Dec 11, 2017 · 4 comments

Comments

@automaticgiant
Copy link

automaticgiant commented Dec 11, 2017

tasks:
  build_providers:
    run:
        when:
          os: osx
        environment:
          DRONE_ARCH: darwin/amd64
    run:
      - command: mkdir -pv ${DRONE_ARCH}
      - command: ./go_buildif.sh github.com/terraform-providers/terraform-provider-http

alternatively, some kind of coalsece(ala tf) string list construct? or something to set a default if unset in the environment clause?
thought would be nice to have a tusk task that works in ci as well as local dev if you don't want to wrap in drone containers.
idk. i'm probably going to go back to original idea of breaking tasks and drone pipeline stage commands out into scripts instead. was original plan but thought tusk tasks seemed betterer.
probably is. it's not a build system or logic system, it's a task runner.

@rliebz
Copy link
Owner

rliebz commented Dec 11, 2017

It looks like you have a duplicated run key. I'm not sure if that's considered valid yaml—Tusk is only going to respect the second one of those, although it should probably throw an error in this scenario.

Either way, consolidating your run clauses should fix the issue:

tasks:
  build_providers:
    run:
      - when:
          os: osx
        environment:
          DRONE_ARCH: darwin/amd64
      - command: mkdir -pv ${DRONE_ARCH}
      - command: ./go_buildif.sh github.com/terraform-providers/terraform-provider-http

@rliebz
Copy link
Owner

rliebz commented Dec 12, 2017

I think that if you're looking for something like Terraform's coalesce, you might be better writing a python script or something similar, which you could still invoke from Tusk if you like the interface:

run: ./my_script.py

As for:

something to set a default if unset in the environment clause?

You can chuck regular old bash scripting into your when clause as a condition:

tasks:
  foo:
    run:
      - when:
          command: test -z "${MY_ENV_VAR}"
        environment:
          MY_ENV_VAR: some_default_value

@rliebz
Copy link
Owner

rliebz commented Jan 4, 2018

The more I look at test -z "${MY_ENV_VAR}", the less I like it.

I'm leaning toward first-class support for environment variables in when clauses, which would look like this:

when:
  environment:
    MY_ENV_VAR_UNSET: ~   # This checks if not set
    MY_ENV_VAR_EMPTY: ""  # This makes sure it was set but empty
    MY_ENV_VAR_STRING: regular_string

Would that fit your use case?

@rliebz
Copy link
Owner

rliebz commented Feb 21, 2018

I added support for environment conditionals in v0.3.3 — There's documentation in the readme.

I'm going to close this, but let me know if this implementation doesn't meet your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants