Add rules
to input
and add some validation
What does this MR do and why?
Turn on the feature flag ci_dynamic_pipeline_inputs
Valid syntax:
spec:
inputs:
deployment_type:
options: ["rolling", "blue_green", "canary"]
default: "rolling"
target_environment:
options: ["development", "staging", "production"]
default: "development"
resource_tier:
rules:
- if: $[[ inputs.target_environment ]] == "development"
options: ["small", "medium"]
default: "small"
- if: $[[ inputs.target_environment ]] == "staging"
options: ["medium", "large"]
default: "medium"
- if: $[[ inputs.target_environment ]] == "production" && $[[ inputs.deployment_type ]] == "canary"
options: ["large", "xlarge", "xxlarge"]
default: "large"
- if: $[[ inputs.target_environment ]] == "production"
options: ["large", "xlarge"]
default: "xlarge"
- options: ["small"]
---
deploy:
script: |
echo "Deploying using $[[ inputs.deployment_type ]] strategy"
echo "Target: $[[ inputs.target_environment ]]"
echo "Resources: $[[ inputs.resource_tier ]]"
Valid syntax with multiple rule conditions:
spec:
inputs:
cloud_provider:
options: ["aws", "gcp", "azure"]
default: "aws"
environment:
options: ["dev", "staging", "prod"]
default: "dev"
instance_type:
rules:
- if: $[[ inputs.cloud_provider ]] == "aws" && $[[ inputs.environment ]] == "dev"
options: ["t3.micro", "t3.small"]
default: "t3.micro"
- if: $[[ inputs.cloud_provider ]] == "aws" && $[[ inputs.environment ]] == "prod"
options: ["m5.large", "m5.xlarge"]
default: "m5.large"
- if: $[[ inputs.cloud_provider ]] == "gcp"
options: ["e2-standard-2", "e2-standard-4"]
default: "e2-standard-2"
- options: ["standard"]
---
provision:
script: echo "Provisioning $[[ inputs.instance_type ]] on $[[ inputs.cloud_provider ]]"
mixed syntax:
spec:
inputs:
region:
options: ["us-east-1", "us-west-2", "eu-west-1"]
default: "us-east-1"
feature_flags:
rules:
- if: $[[ inputs.region ]] == "us-east-1"
options: ["feature_a", "feature_b", "feature_c"]
- if: $[[ inputs.region ]] == "eu-west-1"
options: ["feature_a", "feature_d"]
default: "feature_a"
- options: ["feature_a"]
default: "feature_a"
---
jobby_job:
script: echo "$[[ inputs.region ]]"
Invalid syntax:
spec:
inputs:
bad_rules:
rules:
- if: $[[ inputs.environment ]] == "prod"
invalid_key: "should not be allowed"
options: ["value"]
---
test-job:
script: echo "This should fail validation"
error: This GitLab CI configuration is invalid: header:spec:inputs:bad_rules config rule contains invalid keys: invalid_key.
NOTE: Circular dependencies will be implemented in the next issue for ease of review. We can't do it here because the editor only runs the schema validation and basic parsing, and the circular deps will only be detected when the pipeline actually gets processed.
Issue | Status | Description |
---|---|---|
Keyword support | Add Input class and basic input configuration support |
|
Input Lexme | In Review, %18.5 | Adds Input lexeme to parse inputs syntax in expressions |
Semantic Validation | Planned for %18.6 |
Statement#input_names , validate referenced inputs exist, circular dependency detection |
GraphQL API | Planned | Expose fields in GraphQL, return structured data for MVP |
NOTE: I am creating a spike so we can test this all out in here:
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.