Published on: December 21, 2023
7 min read
Discover, reuse, and contribute CI/CD components effortlessly, enhancing collaboration and efficiency when creating pipeline configurations.
DevSecOps is all about speed – achieving rapid progress in software development. To succeed in DevSecOps, organizations require a well-functioning CI/CD pipeline that teams can utilize to automate their development workflows.
However, crafting pipeline configurations with YAML can be intricate and challenging because YAML isn't a programming language, Developers may find themselves reinventing the wheel each time they try to create new configurations because they don't have visibility into existing configurations and work that others may have already done, resulting in inefficiency.
GitLab 16.7 introduces the CI/CD Catalog (Beta), with the goal of enhancing developer efficiency by addressing three main questions developers encounter when creating pipeline configurations:
The CI/CD Catalog serves as a centralized hub for developers and organizations to share pre-existing CI/CD components and to discover reusable configurations that others may have already developed. Every component published by users will be part of a public catalog accessible to all users, regardless of their organization or project.
This approach promotes cross-organization collaboration, allowing the entire GitLab community to benefit from the wealth of CI components available. It's a powerful step forward in sharing knowledge among GitLab users, enabling developers to harness the collective expertise of the platform.
In addition to reusing components, developers can contribute to the GitLab CI/CD community by creating their own components and publishing them in the catalog. This ensures that others can benefit from their expertise and encourages collaboration across the platform.
1. Opening the CI/CD Component Catalog
Click on “Search or go to...”
Open the catalog by navigating to “Explore > CI/CD Catalog” or visit this catalog page.
Upon accessing the catalog, you'll find a list of CI/CD components projects contributed by your team, organization, or the wider GitLab community.
2. Browsing components
Navigate through the list of components in the CI/CD Catalog or use the Search bar to find components related to a specific topic.
Each component project contains one or multiple components. Opening a component project will display its documentation, providing details on all available components. This includes insights into how to use each component and understanding the expected input parameters.
3. Include the selected components in your .gitlab-ci.yml
Now that you've explored the catalog and selected the desired CI/CD components, integrate them into your project's CI/CD pipeline.
Follow these steps to update your .gitlab-ci.yml file:
Here is an example of YAML code that demonstrates how to include a few components and use them with input parameters.
Have you crafted a valuable configuration that you'd like to share and contribute to your team or the GitLab community? Here are the six steps to make it happen:
Step 1: Create a new project and set it as a component project
Step 2: Create the components
spec
keyword if the component requires input parameters, and the definition of jobs, that may include references to values using the interpolation format $[[ inputs.input-name ]]. Ensure you use three dash lines between the spec header, and job definitions.Here is an example of a deploy.yml
template that gets input parameters:
In this template, we've defined two input parameters, stage
and environment
, both with default values. In the content section, a job is defined that interpolates these input arguments.
Step 3: Create components documentation
Create a README.md file in the root of the project, including information about the components. Explain the component's functionality, detail input parameters, and provide illustrative examples. This ensures clarity for component consumers on how to use them.
This is an example of component documentation:
Additional information can be found in our CI/CD components documentation.
Step 4: Add tests to the components (recommended)
Developing a component follows a standard software development cycle with stages like build, test, and deploy. It's highly recommended to test your components before publishing them. Check out this example test, which queries the GitLab REST API to check whether a component job has been added to the pipeline. Feel free to use it, and consider adding more tests to ensure your components work as expected.
Include all your test jobs in the .gitlab-ci.yml file in your Catalog project.
Step 5: Prepare your CI/CD configuration for publishing
Release
keyword. See the job example:Note: Do not "create release" from GitLab UI since this soon won't be supported for a Component Catalog.
Here is the release job with the when:manual
rule:
Step 6: Publish your components
Once you are satisfied with your components, and all tests have passed successfully, it's time to publish a new version by creating a git tag, so they will be available in the CI/CD Catalog.
Create a Git tag using the semantic versioning format "MAJOR.MINOR.PATCH".
You can create tags through the UI by navigating to Code -> Tags -> New Tag, or via the CLI using git tag
.
Creating the tag will trigger a pipeline that runs the Release job if all tests pass successfully. The component project will then be assigned the version you defined in the tag, and it will appear in the catalog.
For more details on using components from the CI/CD Catalog and maximizing their potential within your projects, refer to the official CI/CD Catalog documentation. This documentation provides in-depth insights into the functionality.
Take a tour of the GitLab CI/CD Catalog.
A special thank you to Dov Hershkovitch and Fabio Pitino for their invaluable content reviews and contributions to this blog post.