Skip to content

bit-tasks/gitlab-pipeline-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bit Tasks for Git CI/CD Pipelines

Example GitLab Pipeline jobs for common Bit and Git CI/CD workflows.

GitLab Support with Bit Docker Image

You can leverage seamless integration of GitLab support through the Bit Docker image. Select from these available images:

  • Latest Stable:

    bitsrc/stable:latest
    
  • Nightly:

    bitsrc/nightly:latest

Setup Guide

  1. Initialize Configuration File: Create .gitlab-ci.yml in your GitLab repository's root and with the code shown below.
  2. Workspace Navigation: Move to the appropriate directory if your workspace isn't at the root of your Git repository. For instance, use cd ws-dir.
  3. Script Initialization: Begin with gitlab.bit.init, as subsequent scripts will depend on it.
  4. CI/CD Variables Setup: Define new CI/CD variables like:

Ensure these variables are correctly configured within your GitLab CI pipeline.

Note: If you set the variables in GitLab project CI/CD variables, there's no need to explicitly define them inside your .gitlab-ci.yml file.

Automating Component Release

Task Example
Initialize Bit bit-init/.gitlab-ci.yml
Bit Verify Components verify/.gitlab-ci.yml
Bit Tag and Export tag-export/.gitlab-ci.yml
Bit Merge Request Build merge-request/.gitlab-ci.yml
Bit Lane Cleanup lane-cleanup/.gitlab-ci.yml
Commit Bitmap commit-bitmap/.gitlab-ci.yml

⬇️ Download Files

Update Workspace Components, External Dependencies and Envs

Task Example
Dependency Update dependency-update/.gitlab-ci.yml

⬇️ Download Files

Sync Git Branches with Bit Lanes

Task Example
Branch Lane branch-lane/.gitlab-ci.yml

⬇️ Download Files

Usage Documentation

1. Bit Initialization: gitlab.bit.init

gitlab.bit.init

Source: script details

The Bit Docker image comes with the latest Bit version pre-installed. Still, the gitlab.bit.init script provides:

  • Verification and possible installation of the relevant version as specified in the engine block of your workspace.jsonc.
  • Initialization of default org and scope variables for further tasks.
  • Execution of the bit install command inside the workspace.

Example

image: bitsrc/stable:latest

variables:
  GIT_USER_NAME: “git_user_name”
  GIT_USER_EMAIL: “git_user_email”

build-job:
  stage: build
  script: 
    - |
      cd my-workspace-dir
      gitlab.bit.init
  rules:
     - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'

2. Bit Verification: gitlab.bit.verify

gitlab.bit.verify

Source: script details

Parameters (Optional)

  • --skip-build: This parameter, like gitlab.bit.verify --skip-build, prevents the bit build command execution.

Example

image: bitsrc/stable:latest

variables:
  GIT_USER_NAME: “git_user_name”
  GIT_USER_EMAIL: “git_user_email”

build-job:
  stage: build
  script: 
    - |
      cd my-workspace-dir
      gitlab.bit.init
      gitlab.bit.verify
  rules:
     - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'

3. Bit Commit Bitmap: gitlab.bit.commit-bitmap

gitlab.bit.commit-bitmap --skip-ci

Source: script details

Parameters (Optional)

  • --skip-push: Avoids pushing changes; useful for tests.
  • --skip-ci: Prevents re-triggering CI on code push, avoiding potential loops.

Example

image: bitsrc/stable:latest

variables:
  GIT_USER_NAME: “git_user_name”
  GIT_USER_EMAIL: “git_user_email”

build-job:
  stage: build
  script: 
    - |
      cd my-workspace-dir
      gitlab.bit.init
      gitlab.bit.commit-bitmap --skip-ci
  rules:
     - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'

4. Bit Merge Request: gitlab.bit.merge-request

gitlab.bit.merge-request

Source: script details

Execute this script when a Merge Request is created. It verifies the components and create a lane in bit.cloud for previewing and testing components.

Example

image: bitsrc/stable:latest

variables:
  GIT_USER_NAME: “git_user_name”
  GIT_USER_EMAIL: “git_user_email”

merge-request-job:
  stage: build
  script: 
    - |
      cd my-workspace-dir
      gitlab.bit.init
      gitlab.bit.merge-request
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

5. Bit Lane Cleanup: gitlab.bit.lane-cleanup

gitlab.bit.lane-cleanup

Source: script details

Execute this script when code is pushed to the main branch. It will detect whether the push is a result of a merge request merge event and will then proceed to clean up the lane.

Example

image: bitsrc/stable:latest

variables:
  GIT_USER_NAME: “git_user_name”
  GIT_USER_EMAIL: “git_user_email”

merge-request-closed-job:
  stage: build
  script: 
    - |
      cd my-workspace-dir
      gitlab.bit.init
      gitlab.bit.lane-cleanup
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'

6. Bit Tag and Export: gitlab.bit.tag-export

gitlab.bit.tag-export

Source: script details

Tag component versions using labels on Merge Requests or within Merge Request/Commit titles. Use version keywords major, minor, patch, and pre-release.

Note: If a Merge Request is merged, track it via its merge commit in the target branch. For the action to detect the version keyword, the merge commit should be the recent one in the commit history.

You can persist soft tagged components by adding --persist flag.

Example

image: bitsrc/stable:latest

variables:
  GIT_USER_NAME: “git_user_name”
  GIT_USER_EMAIL: “git_user_email”

release-components-job:
  stage: build
  script: 
    - |
      cd my-workspace-dir
      gitlab.bit.init
      gitlab.bit.tag-export
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'

7. Bit Branch and Lane: gitlab.bit.branch-lane

gitlab.bit.branch-lane

Source: script details

Execute this script when a new branch is created in Git. It will create a lane in bit.cloud for each new Branch and keep the lane in sync with the components modified in Git.

Example

image: bitsrc/stable:latest

variables:
  GIT_USER_NAME: “git_user_name”
  GIT_USER_EMAIL: “git_user_email”

build-job:
  stage: build
  script: 
    - |
      cd test-ws
      gitlab.bit.init
      gitlab.bit.branch-lane
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push"'

8. Bit Dependency Update: gitlab.bit.dependency-update

gitlab.bit.dependency-update --allow "envs, workspace-components"

Source: script details

Run this script as a scheduled pipeline, which will create a merge request to the specified branch with the updated dependencies.

Parameters (Optional)

  • --allow: Allow different types of dependencies. Options all, external-dependencies, workspace-components, envs. You can also use a combination of one or two values, e.g. gitlab.bit.dependency-update --allow "external-dependencies, workspace-components". Default all.
  • --branch: Branch to check for dependency updates. Default main.

Example

image: bitsrc/stable:latest

variables:
  GIT_USER_NAME: “git_user_name”
  GIT_USER_EMAIL: “git_user_email”

check-updates:
  stage: build
  script: 
    - |
      cd test-ws
      gitlab.bit.init
      gitlab.bit.dependency-update --allow "all" --branch "main"
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'

Contributor Guide

To contribute, make updates to scripts starting with gitlab.bit. in the Bit Docker Image Repository.

To create zip files use the below commands.

chmod +x zip-files.sh
bash ./zip-files.sh

About

Bit GitLab Pipeline Examples for Git CI/CD Pipelines

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages