From 37c0a7410b5309600d7966478f00e0b87e900d5e Mon Sep 17 00:00:00 2001 From: Furkan Ayhan Date: Tue, 8 Nov 2022 08:49:29 +0100 Subject: [PATCH 1/3] Add documentation and CI schema for variables:expand/raw --- app/assets/javascripts/editor/schema/ci.json | 66 ++++++++++++++----- doc/ci/yaml/index.md | 31 +++++++++ .../yaml_tests/negative_tests/variables.yml | 3 + .../yaml_tests/positive_tests/variables.yml | 10 +++ 4 files changed, 94 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/editor/schema/ci.json b/app/assets/javascripts/editor/schema/ci.json index 4c2d6ac30bb376..d83fb1123a8a0e 100644 --- a/app/assets/javascripts/editor/schema/ci.json +++ b/app/assets/javascripts/editor/schema/ci.json @@ -132,7 +132,7 @@ "$ref": "#/definitions/exists" }, "variables": { - "$ref": "#/definitions/variables" + "$ref": "#/definitions/rulesVariables" }, "when": { "type": "string", @@ -690,7 +690,7 @@ "$ref": "#/definitions/exists" }, "variables": { - "$ref": "#/definitions/variables" + "$ref": "#/definitions/rulesVariables" }, "when": { "$ref": "#/definitions/when" @@ -744,6 +744,10 @@ "description": { "type": "string", "markdownDescription": "Explains what the variable is used for, what the acceptable values are. Variables with `description` are prefilled when running a pipeline manually. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesdescription)." + }, + "expand": { + "type": "boolean", + "markdownDescription": "Defines if the variable is expandable or not. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesexpand)." } }, "additionalProperties": false @@ -753,6 +757,49 @@ "additionalProperties": false } }, + "jobVariables": { + "markdownDescription": "Defines variables for a job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variables).", + "type": "object", + "patternProperties": { + ".*": { + "oneOf": [ + { + "type": [ + "string", + "number" + ] + }, + { + "type": "object", + "properties": { + "value": { + "type": "string" + }, + "expand": { + "type": "boolean", + "markdownDescription": "Defines if the variable is expandable or not. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesexpand)." + } + }, + "additionalProperties": false + } + ] + }, + "additionalProperties": false + } + }, + "rulesVariables": { + "markdownDescription": "Defines variables for a rule result. [Learn More](https://docs.gitlab.com/ee/ci/yaml/index.html#rulesvariables).", + "type": "object", + "patternProperties": { + ".*": { + "type": [ + "string", + "number" + ] + }, + "additionalProperties": false + } + }, "if": { "type": "string", "markdownDescription": "Expression to evaluate whether additional attributes should be provided to the job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#rulesif)." @@ -795,19 +842,6 @@ "type": "string" } }, - "variables": { - "markdownDescription": "Defines environment variables. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variables).", - "type": "object", - "patternProperties": { - ".*": { - "type": [ - "string", - "number" - ] - }, - "additionalProperties": false - } - }, "timeout": { "type": "string", "markdownDescription": "Allows you to configure a timeout for a specific job (e.g. `1 minute`, `1h 30m 12s`). [Learn More](https://docs.gitlab.com/ee/ci/yaml/index.html#timeout).", @@ -1170,7 +1204,7 @@ "$ref": "#/definitions/rules" }, "variables": { - "$ref": "#/definitions/variables" + "$ref": "#/definitions/jobVariables" }, "cache": { "$ref": "#/definitions/cache" diff --git a/doc/ci/yaml/index.md b/doc/ci/yaml/index.md index f511a74b24483e..7d1efc9e5ae14e 100644 --- a/doc/ci/yaml/index.md +++ b/doc/ci/yaml/index.md @@ -4261,6 +4261,37 @@ variables: - A global variable defined with `value` but no `description` behaves the same as [`variables`](#variables). +### `variables:expand` + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/353991) in GitLab 15.6 [with a flag](../../administration/feature_flags.md) named `ci_raw_variables_in_yaml_config`. Disabled by default. + +Use the `expand` keyword to define if the variable is expandable or not. (TODO: we may need a dedicated page for raw-variables) + +**Keyword type**: Global and job keyword. You can use it at the global level, and also at the job level. + +**Possible inputs**: + +- `true` (default): The variable is expandable. +- `false`: The variable is not expandable. + +**Example of `variables:expand`**: + +```yaml +variables: + VAR1: value1 + VAR2: value2 $VAR1 + VAR3: + value: value3 $VAR1 + expand: false +``` + +- The result of `VAR2` is `value2 value1`. +- The result of `VAR3` is `value3 $VAR1`. + +**Additional details**: + +- The `expand` keyword can only be used within the global and job-level `variables` keywords. + ### `when` Use `when` to configure the conditions for when jobs run. If not defined in a job, diff --git a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml index a7f23cf0d7342f..7dd7dff19d729b 100644 --- a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml +++ b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml @@ -3,3 +3,6 @@ variables: FOO: value: BAR desc: A single value variable + RAW_VAR: + value: Hello $FOO + expand: okay diff --git a/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/variables.yml b/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/variables.yml index ee71087a72eaab..53d020c432faa2 100644 --- a/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/variables.yml +++ b/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/variables.yml @@ -6,3 +6,13 @@ variables: description: "A single value variable" DEPLOY_ENVIRONMENT: description: "A multi-value variable" + RAW_VAR: + value: "Hello $FOO" + expand: false + +rspec: + script: rspec + variables: + RAW_VAR2: + value: "Hello $DEPLOY_ENVIRONMENT" + expand: false \ No newline at end of file -- GitLab From 81d130a913e05eff0aee1d40f6eeee337ae51c66 Mon Sep 17 00:00:00 2001 From: Marcel Amirault Date: Thu, 10 Nov 2022 12:09:39 +0000 Subject: [PATCH 2/3] Apply 3 suggestion(s) to 2 file(s) --- app/assets/javascripts/editor/schema/ci.json | 2 +- doc/ci/yaml/index.md | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/editor/schema/ci.json b/app/assets/javascripts/editor/schema/ci.json index d83fb1123a8a0e..45f063a2048cdf 100644 --- a/app/assets/javascripts/editor/schema/ci.json +++ b/app/assets/javascripts/editor/schema/ci.json @@ -747,7 +747,7 @@ }, "expand": { "type": "boolean", - "markdownDescription": "Defines if the variable is expandable or not. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesexpand)." + "markdownDescription": "If the variable is expandable or not. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesexpand)." } }, "additionalProperties": false diff --git a/doc/ci/yaml/index.md b/doc/ci/yaml/index.md index 7d1efc9e5ae14e..9444ebeb2fd637 100644 --- a/doc/ci/yaml/index.md +++ b/doc/ci/yaml/index.md @@ -4265,7 +4265,7 @@ variables: > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/353991) in GitLab 15.6 [with a flag](../../administration/feature_flags.md) named `ci_raw_variables_in_yaml_config`. Disabled by default. -Use the `expand` keyword to define if the variable is expandable or not. (TODO: we may need a dedicated page for raw-variables) +Use the `expand` keyword to configure a variable to be expandable or not. **Keyword type**: Global and job keyword. You can use it at the global level, and also at the job level. @@ -4290,7 +4290,8 @@ variables: **Additional details**: -- The `expand` keyword can only be used within the global and job-level `variables` keywords. +- The `expand` keyword can only be used with the global and job-level `variables` keywords. + You can't use it with [`rules:variables`](#rulesvariables) or [`workflow:rules:variables`](#workflowrulesvariables). ### `when` -- GitLab From ded999655a239d9bcc2e56def53861ab6f158668 Mon Sep 17 00:00:00 2001 From: Furkan Ayhan Date: Thu, 10 Nov 2022 16:37:33 +0100 Subject: [PATCH 3/3] Separate CI schema specs --- spec/frontend/editor/schema/ci/ci_schema_spec.js | 6 ++++-- .../schema/ci/yaml_tests/negative_tests/variables.yml | 8 -------- .../negative_tests/variables/invalid_syntax_desc.yml | 4 ++++ .../variables/wrong_syntax_usage_expand.yml | 4 ++++ 4 files changed, 12 insertions(+), 10 deletions(-) delete mode 100644 spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml create mode 100644 spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_syntax_desc.yml create mode 100644 spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/wrong_syntax_usage_expand.yml diff --git a/spec/frontend/editor/schema/ci/ci_schema_spec.js b/spec/frontend/editor/schema/ci/ci_schema_spec.js index b2c9118ddcf4d3..203a00577f1db4 100644 --- a/spec/frontend/editor/schema/ci/ci_schema_spec.js +++ b/spec/frontend/editor/schema/ci/ci_schema_spec.js @@ -37,7 +37,8 @@ import JobWhenYaml from './yaml_tests/positive_tests/job_when.yml'; import ArtifactsNegativeYaml from './yaml_tests/negative_tests/artifacts.yml'; import IncludeNegativeYaml from './yaml_tests/negative_tests/include.yml'; import RulesNegativeYaml from './yaml_tests/negative_tests/rules.yml'; -import VariablesNegativeYaml from './yaml_tests/negative_tests/variables.yml'; +import VariablesInvalidSyntaxDescYaml from './yaml_tests/negative_tests/variables/invalid_syntax_desc.yml'; +import VariablesWrongSyntaxUsageExpand from './yaml_tests/negative_tests/variables/wrong_syntax_usage_expand.yml'; import JobWhenNegativeYaml from './yaml_tests/negative_tests/job_when.yml'; import ProjectPathIncludeEmptyYaml from './yaml_tests/negative_tests/project_path/include/empty.yml'; @@ -137,7 +138,8 @@ describe('negative tests', () => { IncludeNegativeYaml, JobWhenNegativeYaml, RulesNegativeYaml, - VariablesNegativeYaml, + VariablesInvalidSyntaxDescYaml, + VariablesWrongSyntaxUsageExpand, ProjectPathIncludeEmptyYaml, ProjectPathIncludeInvalidVariableYaml, ProjectPathIncludeLeadSlashYaml, diff --git a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml deleted file mode 100644 index 7dd7dff19d729b..00000000000000 --- a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml +++ /dev/null @@ -1,8 +0,0 @@ -# invalid variable (unknown keyword is used) -variables: - FOO: - value: BAR - desc: A single value variable - RAW_VAR: - value: Hello $FOO - expand: okay diff --git a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_syntax_desc.yml b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_syntax_desc.yml new file mode 100644 index 00000000000000..4916a6b354ee64 --- /dev/null +++ b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_syntax_desc.yml @@ -0,0 +1,4 @@ +variables: + FOO: + value: BAR + desc: A single value variable diff --git a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/wrong_syntax_usage_expand.yml b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/wrong_syntax_usage_expand.yml new file mode 100644 index 00000000000000..62bebfa57e7063 --- /dev/null +++ b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/wrong_syntax_usage_expand.yml @@ -0,0 +1,4 @@ +variables: + RAW_VAR: + value: Hello $FOO + expand: okay -- GitLab