-
Suggestion
-
Resolution: Unresolved
-
None
-
None
-
0
-
Currently, it is not possible to use runtime variables in YAML specs. In general YAML kind of already supports using variables - we can usually use them in the same fields where we could use them in UI. However, in fields with context validation, like a project or plan key, Bamboo checks if it exists when executing YAML. Unfortunately, this is not possible as variable substitution is executed when running the plan, and YAML validation is checking if the source plan exists, so it won’t let it pass in this form.
This would be good to use runtime variables in Bamboo Specs Yaml. This would be to try substituting all variables before the Specs are executed. It could be handy if variable substitution is recognised when running the plan with the YAML specs.
Workaround
Below is the scenario which can be implemented using Java Specs
Example: You can define scp common task which can be used in many plans:
public class ScpTaskCommon extends ScpTask { public ScpTaskCommon(String host) { super(); this.fromArtifact(new ArtifactItem().artifact("Linux - example.tar.gz"). sourcePlan(new PlanIdentifier("BRC", "example"))); this.toRemotePath("/data/example"); this.host(host); this.authenticateWithKey("example-user"); this.authenticateWithPassword("example-password"); this.description("Copy Tar.gz File to Remote Location"); } }
And usage:
Plan plan3 = new Plan(project, "plqnwithglobalrepo", "PWGR").projectRepositories("project1demo") //linkedRepositories("demo") .stages(new Stage("Def Stag").jobs(new Job("def job", "DJ") .tasks(new VcsCheckoutTask().addCheckoutOfDefaultRepository(), new ScpTaskCommon("192.168.0.1") ) .artifacts(new Artifact("newfile").copyPatterns("newfile.txt")) )); Plan plan4 = new Plan(project, "plqnwithprojectrepo", "PWPR").projectRepositories("project1demo") .stages(new Stage("Def Stag").jobs(new Job("def job", "DJ") .tasks(new VcsCheckoutTask().addCheckoutOfDefaultRepository(), new ScpTaskCommon("192.168.1.21") ) .artifacts(new Artifact("newfile").copyPatterns("newfile.txt")) ));
How runtime variables can be used using YAML/JAVA specs?
We can’t interpolate the planKey variable to yaml or java specs because Bamboo reads specs, gets the plan key from specs, finds the plan in Bamboo with this key and then the plan in Bamboo is updated with the new version from specs and You can't use a runtime variable in a context that has to be defined when you create a plan, i.e. you can't have a variable in an artifact name.