tasklib: Ensure we always set env['environment'] when deploy is run

And a small refactor while we're at it