fly: support `-i/--instance-var` for all commands that accept a pipeline reference
Summary
fly set-pipeline identifies an instanced pipeline via -p <name> plus one or more
-i key=value flags. All other commands that target a pipeline, job, or resource
only accept instance vars embedded in the reference string, e.g.
-p my-pipeline/branch:main or -j my-pipeline/branch:main/my-job.
This inconsistency makes scripting awkward: the same instanced pipeline has to be
addressed with two different syntaxes depending on the command, and values
containing :, ,, or / require careful quoting in the embedded form.
Proposal
Add a repeatable -i/--instance-var NAME=YAML flag to every command that currently
parses instance vars out of the pipeline reference, using the same format and
semantics as set-pipeline:
# existing (keeps working)
fly -t ci trigger-job -j my-pipeline/branch:main/unit
# new
fly -t ci trigger-job -j my-pipeline/unit -i branch=main
fly -t ci get-pipeline -p my-pipeline -i branch=mainBehaviour
- Values are parsed as YAML; dotted keys are expanded
(
-i env.region=eu→{"env":{"region":"eu"}}), identical toset-pipeline. - Specifying instance vars both in the reference and via
-iis an error (no implicit merging). -iwithout a pipeline/job/resource reference is an error, as is-icombined with--all.- For commands with multiple possible targets (
builds,hijack,clear-versions),-iapplies to the one target that is set. - The existing
name/key:valuesyntax remains fully supported (additive change).
Commands to update
Pipeline reference (-p/--pipeline)
-
archive-pipeline(optional-p, mutually exclusive with--all) -
checklist -
destroy-pipeline -
expose-pipeline -
get-pipeline -
hide-pipeline -
jobs -
pause-pipeline(optional-p, mutually exclusive with--all) -
paused-jobs -
resources -
unpause-pipeline(optional-p, mutually exclusive with--all)
Job reference (-j/--job)
-
abort-build -
clear-task-cache -
pause-job -
rerun-build -
schedule-job -
trigger-job -
unpause-job -
watch
Resource / resource-type reference (-r)
-
check-resource -
check-resource-type -
clear-resource-cache -
disable-resource-version -
enable-resource-version -
pin-resource -
resource-versions -
unpin-resource
Commands with more than one possible target
-
builds(-jor-p) -
clear-versions(--resourceor--resource-type) -
hijack(-jor-c)
Special case (to be discussed)
-
execute(-j/--inputs-from):-iis already taken by--input, so only the long form--instance-varcould be added.
Not affected
set-pipeline– already supports-i.order-instanced-pipelines–-palready takes instance vars only.-u/--urlonwatch/hijack– instance vars are taken from the URL.
Implementation notes
PipelineFlag,JobFlag, andResourceFlagparse instance vars inUnmarshalFlag, which cannot see other flags. The-ivalues therefore need to be applied to the parsedatc.PipelineRefat the start ofExecute().- A shared helper in
fly/commands/internal/flaghelpers(e.g.ApplyInstanceVars(ref *atc.PipelineRef, pairs []YAMLVariablePairFlag) error) can enforce the rules above; the pairs-to-atc.InstanceVarsconversion can be extracted fromset_pipeline.goand reused there. - Tests: unit tests for the helper; integration tests in
fly/integrationmirroring the existingname/branch:mastercases with-p name -i branch=master. - Docs: update the instanced pipelines section of the fly docs.
Open questions
- Should combining both syntaxes be an error (proposed) or should the vars be merged?
- Should
execute --inputs-fromget the long-only--instance-varflag?
Context
Discord Discussion: https://discord.com/channels/219899946617274369/604330872992432150/1554381930307395669
Source: concourse/concourse