diff --git a/app/assets/javascripts/editor/schema/ci.json b/app/assets/javascripts/editor/schema/ci.json index 4c2d6ac30bb3765e335fa615307ba21b673e6c52..45f063a2048cdf06b7ed9e3c6e4d5082c683e8f7 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": "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 f511a74b24483ed5ce469f9a0fd531e4571f6202..9444ebeb2fd63760a51e7d4f4560ea1fa938142f 100644 --- a/doc/ci/yaml/index.md +++ b/doc/ci/yaml/index.md @@ -4261,6 +4261,38 @@ 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 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. + +**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 with the global and job-level `variables` keywords. + You can't use it with [`rules:variables`](#rulesvariables) or [`workflow:rules:variables`](#workflowrulesvariables). + ### `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/ci_schema_spec.js b/spec/frontend/editor/schema/ci/ci_schema_spec.js index b2c9118ddcf4d3e88c1e09c6245f0b88f484371f..203a00577f1db41ae130780b20cf30fce4ad1bb9 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/invalid_syntax_desc.yml similarity index 59% rename from spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml rename to spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_syntax_desc.yml index a7f23cf0d7342f793783a31034bd23a89d807085..4916a6b354ee64a26c1b1229390e24e5bbbe5da2 100644 --- a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables.yml +++ b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_syntax_desc.yml @@ -1,4 +1,3 @@ -# invalid variable (unknown keyword is used) variables: FOO: value: BAR 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 0000000000000000000000000000000000000000..62bebfa57e7063d444b26d702ba7e51379edc683 --- /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 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 ee71087a72eaab6f29c071f6a6ea9ba2741839b3..53d020c432faa2dbc0575db27f0c7fdf480b002d 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