GitLab CI Functions: Reusable Steps for Pipelines
GitLab CI/CD shipped a feature called Steps in GitLab 17.11 (April 2025). The marketing team renamed it Functions. Functions are reusable, composable units. They replace traditional script blocks in a .gitlab-ci.yml file. This makes pipelines more modular, testable, and maintainable.
A Function is defined in a step.yml file. A triple dash (---) splits it into two parts. The first is a specification, like a function signature. The second is an implementation, like a function body. The specification declares inputs and outputs with strict typing. The types are string, number, boolean, or array. Inputs can have defaults or be required. Outputs return structured data:
spec:
inputs:
greeting:
type: string
default: "hello, world"
outputs:
message:
type: string
---
exec:
command:
- echo '{"name":"message","value":"${{inputs.greeting}}"}' | tee ${{output_file}}
This function is called hello. It takes an optional greeting input and outputs a message. A job invokes it with the run keyword:
hello-world:
run:
- name: hello_world
step: path/to/hello/step.yml
inputs:
greeting: "hi, GitLab"
Functions can execute commands. They support bash, docker, and Terraform. They can also orchestrate other functions. A function has access to CI/CD variables, environment variables, and resources like the file system. Inputs support expressions such as ${{inputs.greeting}} for dynamic behavior. Predefined interpolation functions like expand_vars and truncate add flexibility.
Functions are built for reuse across pipelines. You can use them locally, in GitLab.com repositories, or from other Git sources. They integrate with CI/CD Components, which enables complex workflows. At the same time, they stay independent. A function can be versioned and shared via the CI/CD Catalog. This streamlines pipeline maintenance.
The feature is experimental. Breaking changes are tracked in the changelog. One known issue exists: some Docker images lack trusted root certificates. Users must install them or bake them into the job's image.
Functions run in job-defined containers. They give pipelines typed, reusable units with clear inputs and outputs. But their experimental status warrants caution. To dig deeper, follow this tutorial. It is easy to work through.