{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://gitlab.com/.gitlab-ci.yml",
    "title": "Gitlab CI configuration",
    "description": "Gitlab has a built-in solution for doing CI called Gitlab CI. It is configured by supplying a file called `.gitlab-ci.yml`, which will list all the jobs that are going to run for the project. A full list of all options can be found at https://docs.gitlab.com/ee/ci/yaml/. You can read more about Gitlab CI at https://docs.gitlab.com/ee/ci/README.html.",
    "type": "object",
    "properties": {
        "$schema": {
            "type": "string",
            "format": "uri"
        },
        "image": {
            "$ref": "#/definitions/image"
        },
        "services": {
            "$ref": "#/definitions/services"
        },
        "before_script": {
            "$ref": "#/definitions/before_script"
        },
        "after_script": {
            "$ref": "#/definitions/after_script"
        },
        "variables": {
            "$ref": "#/definitions/variables"
        },
        "cache": {
            "$ref": "#/definitions/cache"
        },
        "stages": {
            "type": "array",
            "description": "Groups jobs into stages. All jobs in one stage must complete before next stage is executed. Defaults to ['build', 'test', 'deploy'].",
            "default": [
                "build",
                "test",
                "deploy"
            ],
            "items": {
                "type": "string"
            },
            "_uniqueItems": true,
            "minItems": 1
        },
        "include": {
            "description": "Can be string or array of strings which should be an URL or local file reference (e.g. '/templates/ci-template.yml'). The external content will be fetched, included and evaluated along the `.gitlab-ci.yml`.",
            "default": [],
            "oneOf": [
                {
                    "type": "string",
                    "format": "uri-reference",
                    "pattern": "^(https?://|/).+"
                },
                {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "format": "uri-reference",
                        "pattern": "^(https?://|/).+"
                    }
                }
            ]
        },
        "pages": {
            "$ref": "#/definitions/job",
            "description": "A special job used to upload static sites to Gitlab pages. Requires a `public/` directory with `artifacts.path` pointing to it."
        }
    },
    "patternProperties": {
        "^[.]": {
            "$ref": "#/definitions/job_template"
        }
    },
    "additionalProperties": {
        "$ref": "#/definitions/job"
    },
    "definitions": {
        "string_file_list": {
            "oneOf": [
                {
                    "type": "string"
                },
                {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            ]
        },
        "image": {
            "oneOf": [
                {
                    "type": "string",
                    "minLength": 1,
                    "description": "Full name of the image that should be used. It should contain the Registry part if needed."
                },
                {
                    "type": "object",
                    "description": "Specifies the docker image to use for the job or globally for all jobs. Job configuration takes precedence over global setting. Requires a certain kind of Gitlab runner executor.",
                    "additionalProperties": false,
                    "properties": {
                        "name": {
                            "type": "string",
                            "minLength": 1,
                            "description": "Full name of the image that should be used. It should contain the Registry part if needed."
                        },
                        "entrypoint": {
                            "type": "array",
                            "description": "Command or script that should be executed as the container's entrypoint. It will be translated to Docker's --entrypoint option while creating the container. The syntax is similar to Dockerfile's ENTRYPOINT directive, where each shell token is a separate string in the array.",
                            "minItems": 1
                        }
                    },
                    "required": [
                        "name"
                    ]
                }
            ],
            "description": "Specifies the docker image to use for the job or globally for all jobs. Job configuration takes precedence over global setting. Requires a certain kind of Gitlab runner executor."
        },
        "services": {
            "type": "array",
            "description": "Similar to `image` property, but will link the specified services to the `image` container.",
            "items": {
                "oneOf": [
                    {
                        "type": "string",
                        "minLength": 1,
                        "description": "Full name of the image that should be used. It should contain the Registry part if needed."
                    },
                    {
                        "type": "object",
                        "description": "",
                        "additionalProperties": false,
                        "properties": {
                            "name": {
                                "type": "string",
                                "description": "Full name of the image that should be used. It should contain the Registry part if needed.",
                                "minLength": 1
                            },
                            "entrypoint": {
                                "type": "array",
                                "description": "Command or script that should be executed as the container's entrypoint. It will be translated to Docker's --entrypoint option while creating the container. The syntax is similar to Dockerfile's ENTRYPOINT directive, where each shell token is a separate string in the array.",
                                "minItems": 1,
                                "items": {
                                    "type": "string"
                                }
                            },
                            "command": {
                                "type": "array",
                                "description": "Command or script that should be used as the container's command. It will be translated to arguments passed to Docker after the image's name. The syntax is similar to Dockerfile's CMD directive, where each shell token is a separate string in the array.",
                                "minItems": 1,
                                "items": {
                                    "type": "string"
                                }
                            },
                            "alias": {
                                "type": "string",
                                "description": "Additional alias that can be used to access the service from the job's container. Read Accessing the services for more information.",
                                "minLength": 1
                            }
                        },
                        "required": [
                            "name"
                        ]
                    }
                ]
            }
        },
        "before_script": {
            "type": "array",
            "description": "Defines scripts that should run *before* the job. Can be set globally or per job.",
            "items": {
                "type": "string"
            }
        },
        "after_script": {
            "type": "array",
            "description": "Defines scripts that should run *after* the job. Can be set globally or per job.",
            "items": {
                "type": "string"
            }
        },
        "variables": {
            "type": "object",
            "description": "Defines environment variables for specific jobs or globally. Job level property overrides global variables. If a job sets `variables: {}`, all global variables are turned off.",
            "additionalProperties": {
                "type": "string"
            }
        },
        "cache": {
            "type": "object",
            "description": "Specify files or directories to cache between jobs. Can be set globally or per job.",
            "additionalProperties": false,
            "properties": {
                "paths": {
                    "type": "array",
                    "description": "List of files or paths to cache.",
                    "items": {
                        "type": "string"
                    }
                },
                "key": {
                    "type": "string",
                    "description": "Unique cache ID, to allow e.g. specific branch or job cache. Environment variables can be used to set up unique keys (e.g. \"$CI_COMMIT_REF_SLUG\" for per branch cache)."
                },
                "untracked": {
                    "type": "boolean",
                    "description": "Set to `true` to cache untracked files.",
                    "default": false
                },
                "policy": {
                    "type": "string",
                    "description": "Determines the strategy for downloading and updating the cache.",
                    "default": "pull-push",
                    "oneOf": [
                        {
                            "enum": [
                                "pull"
                            ],
                            "description": "Pull will download cache but skip uploading after job completes."
                        },
                        {
                            "enum": [
                                "push"
                            ],
                            "description": "Push will skip downloading cache and always recreate cache after job completes."
                        },
                        {
                            "enum": [
                                "pull-push"
                            ],
                            "description": "Pull-push will both download cache at job start and upload cache on job success."
                        }
                    ]
                }
            }
        },
        "filter_refs": {
            "type": "array",
            "description": "Filter job by different keywords that determine origin or state, or by supplying string/regex to check against branch/tag names.",
            "items": {
                "anyOf": [
                    {
                        "oneOf": [
                            {
                                "enum": [
                                    "branches"
                                ],
                                "description": "When a branch is pushed."
                            },
                            {
                                "enum": [
                                    "tags"
                                ],
                                "description": "When a tag is pushed."
                            },
                            {
                                "enum": [
                                    "api"
                                ],
                                "description": "When a pipeline has been triggered by a second pipelines API (not triggers API)."
                            },
                            {
                                "enum": [
                                    "external"
                                ],
                                "description": "When using CI services other than Gitlab"
                            },
                            {
                                "enum": [
                                    "pipelines"
                                ],
                                "description": "For multi-project triggers, created using the API with 'CI_JOB_TOKEN'."
                            },
                            {
                                "enum": [
                                    "pushes"
                                ],
                                "description": "Pipeline is triggered by a `git push` by the user"
                            },
                            {
                                "enum": [
                                    "schedules"
                                ],
                                "description": "For scheduled pipelines."
                            },
                            {
                                "enum": [
                                    "triggers"
                                ],
                                "description": "For pipelines created using a trigger token."
                            },
                            {
                                "enum": [
                                    "web"
                                ],
                                "description": "For pipelines created using *Run pipeline* button in Gitlab UI (under your project's *Pipelines*)."
                            }
                        ]
                    },
                    {
                        "type": "string",
                        "description": "String or regular expression to match against tag or branch names."
                    }
                ]
            }
        },
        "filter": {
            "oneOf": [
                {
                    "$ref": "#/definitions/filter_refs"
                },
                {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "refs": {
                            "$ref": "#/definitions/filter_refs"
                        },
                        "kubernetes": {
                            "enum": [
                                "active"
                            ],
                            "description": "Filter job based on if Kubernetes integration is active."
                        },
                        "variables": {
                            "type": "array",
                            "description": "Filter job by checking comparing values of environment variables. Read more about variable expressions: https://docs.gitlab.com/ee/ci/variables/README.html#variables-expressions",
                            "items": {
                                "type": "string"
                            }
                        },
                        "changes": {
                            "type": "array",
                            "description": "Filter job creation based on files that were modified in a git push.",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                }
            ]
        },
        "retry_max": {
            "type": "integer",
            "description": "The number of times the job will be retried if it fails. Defaults to 0 and can max be retried 2 times (3 times total).",
            "default": 0,
            "minimum": 0,
            "maximum": 2
        },
        "retry_errors": {
            "oneOf": [
                {
                    "enum": [
                        "always"
                    ],
                    "description": "Retry on any failure (default)."
                },
                {
                    "enum": [
                        "unknown_failure"
                    ],
                    "description": "Retry when the failure reason is unknown."
                },
                {
                    "enum": [
                        "script_failure"
                    ],
                    "description": "Retry when the script failed."
                },
                {
                    "enum": [
                        "api_failure"
                    ],
                    "description": "Retry on API failure."
                },
                {
                    "enum": [
                        "stuck_or_timeout_failure"
                    ],
                    "description": "Retry when the job got stuck or timed out."
                },
                {
                    "enum": [
                        "runner_system_failure"
                    ],
                    "description": "Retry if there was a runner system failure (e.g. setting up the job failed)."
                },
                {
                    "enum": [
                        "missing_dependency_failure"
                    ],
                    "description": "Retry if a dependency was missing."
                },
                {
                    "enum": [
                        "runner_unsupported"
                    ],
                    "description": "Retry if the runner was unsupported."
                }
            ]
        },
        "job": {
            "allOf": [
                {
                    "$ref": "#/definitions/job_template"
                },
                {
                    "anyOf": [
                        {
                            "required": [
                                "script"
                            ]
                        },
                        {
                            "required": [
                                "extends"
                            ]
                        }
                    ]
                }
            ]
        },
        "job_template": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "image": {
                    "$ref": "#/definitions/image"
                },
                "services": {
                    "$ref": "#/definitions/services"
                },
                "before_script": {
                    "$ref": "#/definitions/before_script"
                },
                "after_script": {
                    "$ref": "#/definitions/after_script"
                },
                "variables": {
                    "$ref": "#/definitions/variables"
                },
                "cache": {
                    "$ref": "#/definitions/cache"
                },
                "script": {
                    "description": "Shell scripts executed by the Runner. The only required property of jobs. Be careful with special characters (e.g. `:`, `{`, `}`, `&`) and use single or double quotes to avoid issues.",
                    "oneOf": [
                        {
                            "type": "string",
                            "minLength": 1
                        },
                        {
                            "type": "array",
                            "items": {
                                "type": "string"
                            },
                            "minItems": 1
                        }
                    ]
                },
                "stage": {
                    "type": "string",
                    "description": "Define what stage the job will run in.",
                    "default": "test"
                },
                "only": {
                    "$ref": "#/definitions/filter",
                    "description": "Job will run *only* when these filtering options match."
                },
                "extends": {
                    "type": "string",
                    "description": "The name of a job to inherit configuration from."
                },
                "except": {
                    "$ref": "#/definitions/filter",
                    "description": "Job will run *except* for when these filtering options match."
                },
                "tags": {
                    "type": "array",
                    "description": "Used to select runners from the list of available runners. A runner must have all tags listed here to run the job.",
                    "items": {
                        "type": "string"
                    }
                },
                "allow_failure": {
                    "type": "boolean",
                    "description": "Setting this option to true will allow the job to fail while still letting the pipeline pass.",
                    "default": false
                },
                "when": {
                    "description": "Describes the conditions for when to run the job. Defaults to 'on_success'.",
                    "default": "on_success",
                    "oneOf": [
                        {
                            "enum": [
                                "on_success"
                            ],
                            "description": "Execute job only when all jobs from prior stages succeed."
                        },
                        {
                            "enum": [
                                "on_failure"
                            ],
                            "description": "Execute job when at least one job from prior stages fails."
                        },
                        {
                            "enum": [
                                "always"
                            ],
                            "description": "Execute job regardless of the status from prior stages."
                        },
                        {
                            "enum": [
                                "manual"
                            ],
                            "description": "Execute the job manually from Gitlab UI or API. Read more: https://docs.gitlab.com/ee/ci/yaml/#when-manual"
                        },
                        {
                            "enum": [
                                "delayed"
                            ],
                            "description": "Execute a job after the time limit in 'start_in' expires. Read more: https://docs.gitlab.com/ee/ci/yaml/#when-delayed"
                        }
                    ]
                },
                "start_in": {
                    "type": "string",
                    "description": "Used in conjunction with 'when: delayed' to set how long to delay before starting a job.",
                    "minLength": 1
                },
                "dependencies": {
                    "type": "array",
                    "description": "Specify a list of job names from earlier stages from which artifacts should be loaded. By default, all previous artifacts are passed. Use an empty array to skip downloading artifacts.",
                    "items": {
                        "type": "string"
                    }
                },
                "artifacts": {
                    "type": "object",
                    "description": "Used to specify a list of files and directories that should be attached to the job if it succeeds. Artifacts are sent to Gitlab where they can be downloaded.",
                    "additionalProperties": false,
                    "properties": {
                        "paths": {
                            "type": "array",
                            "description": "A list of paths to files/folders that should be included in the artifact.",
                            "items": {
                                "type": "string"
                            },
                            "minLength": 1
                        },
                        "name": {
                            "type": "string",
                            "description": "Name for the archive created on job success. Can use variables in the name, e.g. '$CI_JOB_NAME'"
                        },
                        "untracked": {
                            "type": "boolean",
                            "description": "Whether to add all untracked files (along with 'artifacts.paths') to the artifact.",
                            "default": false
                        },
                        "when": {
                            "description": "Configure when artifacts are uploaded depended on job status.",
                            "default": "on_success",
                            "oneOf": [
                                {
                                    "enum": [
                                        "on_success"
                                    ],
                                    "description": "Upload artifacts only when the job succeeds (this is the default)."
                                },
                                {
                                    "enum": [
                                        "on_failure"
                                    ],
                                    "description": "Upload artifacts only when the job fails."
                                },
                                {
                                    "enum": [
                                        "always"
                                    ],
                                    "description": "Upload artifacts regardless of job status."
                                }
                            ]
                        },
                        "expire_in": {
                            "type": "string",
                            "description": "How long artifacts should be kept. They are saved 30 days by default. Artifacts that have expired are removed periodically via cron job. Supports a wide variety of formats, e.g. '1 week', '3 mins 4 sec', '2 hrs 20 min', '2h20min', '6 mos 1 day', '47 yrs 6 mos and 4d', '3 weeks and 2 days'.",
                            "default": "30 days"
                        },
                        "reports": {
                            "type": "object",
                            "description": "Reports will be uploaded as artifacts, and often displayed in the Gitlab UI, such as in Merge Requests.",
                            "additionalProperties": false,
                            "properties": {
                                "junit": {
                                    "description": "Path for file(s) that should be parsed as JUnit XML result",
                                    "oneOf": [
                                        {
                                            "type": "string",
                                            "description": "Path to a single XML file"
                                        },
                                        {
                                            "type": "array",
                                            "description": "A list of paths to XML files that will automatically be concatenated into a single file",
                                            "items": {
                                                "type": "string"
                                            },
                                            "minLength": 1
                                        }
                                    ]
                                },
                                "codequality": {
                                    "$ref": "#/definitions/string_file_list",
                                    "description": "Path to file or list of files with code quality report(s) (such as Code Climate)."
                                },
                                "sast": {
                                    "$ref": "#/definitions/string_file_list",
                                    "description": "Path to file or list of files with SAST vulnerabilities report(s)."
                                },
                                "dependency_scanning": {
                                    "$ref": "#/definitions/string_file_list",
                                    "description": "Path to file or list of files with Dependency scanning vulnerabilities report(s)."
                                },
                                "container_scanning": {
                                    "$ref": "#/definitions/string_file_list",
                                    "description": "Path to file or list of files with Container scanning vulnerabilities report(s)."
                                },
                                "dast": {
                                    "$ref": "#/definitions/string_file_list",
                                    "description": "Path to file or list of files with DAST vulnerabilities report(s)."
                                },
                                "license_management": {
                                    "$ref": "#/definitions/string_file_list",
                                    "description": "Path to file or list of files with license report(s)."
                                },
                                "performance": {
                                    "$ref": "#/definitions/string_file_list",
                                    "description": "Path to file or list of files with performance metrics report(s)."
                                }
                            }
                        }
                    }
                },
                "environment": {
                    "type": "object",
                    "description": "Used to associate environment metadata with a deploy. Environment can have a name and URL attached to it, and will be displayed under /environments under the project.",
                    "additionalProperties": false,
                    "properties": {
                        "name": {
                            "type": "string",
                            "description": "The name of the environment, e.g. 'qa', 'staging', 'production'.",
                            "minLength": 1
                        },
                        "url": {
                            "type": "string",
                            "description": "When set, this will expose buttons in various places for the current environment in Gitlab, that will take you to the defined URL.",
                            "format": "uri",
                            "pattern": "^https?://.+"
                        },
                        "on_stop": {
                            "type": "string",
                            "description": "The name of a job to execute when the environment is about to be stopped."
                        },
                        "action": {
                            "enum": [
                                "stop"
                            ],
                            "description": "Stops this environment so that it is inactive."
                        }
                    },
                    "required": [
                        "name"
                    ]
                },
                "coverage": {
                    "type": "string",
                    "description": "Must be a regular expression, optionally but recommended to be quoted, and must be surrounded with '/'. Example: '/Code coverage: \\d+\\.\\d+/'",
                    "format": "regex",
                    "pattern": "^/.+/$"
                },
                "retry": {
                    "description": "Retry a job if it fails. Can be a simple integer or object definition.",
                    "oneOf": [
                        {
                            "$ref": "#/definitions/retry_max"
                        },
                        {
                            "type": "object",
                            "additionalProperties": false,
                            "properties": {
                                "max": {
                                    "$ref": "#/definitions/retry_max"
                                },
                                "when": {
                                    "description": "Either a single or array of error types to trigger job retry.",
                                    "oneOf": [
                                        {
                                            "$ref": "#/definitions/retry_errors"
                                        },
                                        {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/retry_errors"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    ]
                },
                "parallel": {
                    "type": "integer",
                    "description": "Parallel will split up a single job into several, and provide `CI_NODE_INDEX` and `CI_NODE_TOTAL` environment variables for the running jobs.",
                    "default": 0,
                    "minimum": 2,
                    "maximum": 50
                }
            },
            "oneOf": [
                {
                    "properties": {
                        "when": {
                            "enum": [
                                "delayed"
                            ]
                        }
                    },
                    "required": [
                        "when",
                        "start_in"
                    ]
                },
                {
                    "properties": {
                        "when": {
                            "not": {
                                "enum": [
                                    "delayed"
                                ]
                            }
                        }
                    }
                }
            ]
        }
    }
}