commit 384cbe6028c44ae286c3d3a9e2f71276c6132510 Author: GitLab Date: Wed Mar 19 11:40:54 2025 +0100 Initialized from 'GitLab CI/CD components' project template Template repository: https://gitlab.com/gitlab-org/project-templates/gitlab-component-template Commit SHA: b8b0a4a1821acf43f82912e4bd00a38cea90aa62 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..e983395 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,44 @@ +workflow: + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS + when: never + - when: always + +include: + # include the component located in the current project from the current SHA + - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/my-component@$CI_COMMIT_SHA + inputs: + job_name: "component job of my-component" + stage: build + +stages: + - build + - test + - release + +ensure-job-added: + stage: test + image: badouralix/curl-jq + rules: + # project must be public for `curl` to access the API; using `CI_JOB_TOKEN` is insufficient! + - if: $CI_PROJECT_VISIBILITY != "public" + when: never + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS + when: never + - when: always + script: | + url="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/jobs" + curl --fail --show-error --silent "$url" | + jq --exit-status 'map(select(.name | contains("component job of my-component"))) | length >= 1' + +create-release: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + rules: + - if: $CI_COMMIT_TAG + script: echo "Creating release $CI_COMMIT_TAG" + release: + tag_name: $CI_COMMIT_TAG + description: "Release $CI_COMMIT_TAG of components repository $CI_PROJECT_PATH" diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..0e6178b --- /dev/null +++ b/LICENCE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..71488c4 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# Gitlab component template + + + + + + +## Components + +### `` + +Use this component to ``. + +To add this component to your CI/CD pipeline, add the following include entry to your +project's CI/CD configuration: + +```yaml +include: + - component: https://gitlab.com//@ +``` + +Where `` is the release tag you want to use ([releases list](https://gitlab.com//-/releases)). + +## Inputs + +The template contains some optional [inputs](https://docs.gitlab.com/ee/ci/yaml/inputs.html): + + + +| Input | Default value | Description | +|------------|------------------|-------------| +| `job_name` | `job-template` | The job name. | +| `image` | `busybox:latest` | The container image to use to run the job. | +| `stage` | `test` | The stage name for the job. | + +## Documentation + +This project includes a MVC structure to help you get started with [Gitlab CI/CD components](https://docs.gitlab.com/ee/ci/components/). +The template provides the basic file structure to create your own single component. +This project should be public, or one of the jobs in the project's pipeline won't work. + +## Licence + +The licence can be changed. By default this project has the [MIT Licence](./LICENCE). + diff --git a/templates/my-component.yml b/templates/my-component.yml new file mode 100644 index 0000000..c57630c --- /dev/null +++ b/templates/my-component.yml @@ -0,0 +1,23 @@ +spec: + inputs: + # These are examples of inputs. + job_name: + default: job-template + image: + default: busybox:latest + stage: + default: test + +--- +# This is an example of a job using inputs +# use variables with this syntax : $[[ inputs.xxx ]] +$[[ inputs.job_name ]]: + image: $[[ inputs.image ]] + stage: $[[ inputs.stage ]] + script: + - echo "Starting job $[[ inputs.job_name ]]" + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS + when: never + - when: always