Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kgoksal/gitlab-ci-cd-templates
GitLab CI&CD Examples
https://github.com/kgoksal/gitlab-ci-cd-templates
Last synced: about 1 month ago
JSON representation
GitLab CI&CD Examples
- Host: GitHub
- URL: https://github.com/kgoksal/gitlab-ci-cd-templates
- Owner: KGoksal
- Created: 2024-08-09T01:57:54.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-17T04:50:19.000Z (4 months ago)
- Last Synced: 2024-08-17T05:41:14.065Z (4 months ago)
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GitLab CI/CD Configuration Examples
This repository includes two examples of GitLab CI/CD configuration files (``.gitlab-ci.yml``) for different scenarios. Below is an overview of each configuration:
## Example 1: Build, Test, and Deploy Pipeline
```
# .gitlab-ci.yml
# Define stages of the pipeline
stages:
- build
- test
- deploy# Job to build the project
build_job:
stage: build
script:
- echo "Building the project..."# Job to run tests
test_job:
stage: test
script:
- echo "Running tests..."# Job to deploy to production
deploy_production:
stage: deploy
script:
- echo "Deploying to production..."
environment:
name: production
url: https://example.com
only:
- master # Deploy only on changes to the master branch
```
### Explanation:
- **Stages Definition**: Defines three stages: `build`, `test`, and `deploy`.
- **Build Job (`build_job`)**: Executes a script to build the project.
- **Test Job (`test_job`)**: Executes a script to run tests.
- **Deploy Job (`deploy_production`)**: Deploys to the `production` environment with a specified URL (`https://example.com`). Runs only when changes are made to the `master` branch.## Example 2: Dockerized Build and Test Pipeline
```
# .gitlab-ci2.yml
# Define stages of the pipeline
stages:
- build
- test# Define variables (optional)
variables:
DOCKER_DRIVER: overlay2# Job to build the Docker image
build_job:
stage: build
image: docker:stable # Use Docker in a Docker image
services:
- docker:dind # Enable Docker-in-Docker
script:
- docker build -t my-app . # Build Docker image named my-app# Job to run tests with Node.js
test_job:
stage: test
image: node:14 # Use Node.js 14 image
script:
- npm install # Install dependencies
- npm test # Run tests
```### Explanation:
- **Stages Definition**: Defines two stages: `build` and `test`.
- **Variables Definition**: Sets a Docker driver variable (`DOCKER_DRIVER`) to `overlay2`.
- **Build Job (`build_job`)**: Uses the `docker:stable` image to build a Docker image named `my-app`.
- **Test Job (`test_job`)**: Uses the `node:14` image to install dependencies and run tests with npm.