Example GitLab Pipeline jobs for common Bit and Git CI/CD workflows.
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
- Initialize Configuration File: Create
.gitlab-ci.ymlin your GitLab repository's root and with the code shown below. - 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. - Script Initialization: Begin with
gitlab.bit.init, as subsequent scripts will depend on it. - CI/CD Variables Setup: Define new CI/CD variables like:
GITLAB_TOKEN: Project Access Token or Personal Access TokenBIT_CLOUD_ACCESS_TOKENYou need BIT_CLOUD_ACCESS_TOKEN (docs).GIT_USER_NAMEGIT_USER_EMAIL
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.ymlfile.
| 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 |
| Task | Example |
|---|---|
| Dependency Update | dependency-update/.gitlab-ci.yml |
| Task | Example |
|---|---|
| Branch Lane | branch-lane/.gitlab-ci.yml |
gitlab.bit.initSource: 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
engineblock of yourworkspace.jsonc. - Initialization of default
organdscopevariables for further tasks. - Execution of the
bit installcommand inside the workspace.
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"'gitlab.bit.verifySource: script details
--skip-build: This parameter, likegitlab.bit.verify --skip-build, prevents thebit buildcommand execution.
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"'gitlab.bit.commit-bitmap --skip-ciSource: script details
--skip-push: Avoids pushing changes; useful for tests.--skip-ci: Prevents re-triggering CI on code push, avoiding potential loops.
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"'gitlab.bit.merge-requestSource: 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.
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"'gitlab.bit.lane-cleanupSource: 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.
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"'gitlab.bit.tag-exportSource: 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 commitin the target branch. For the action to detect the version keyword, themerge commitshould be the recent one in the commit history.
You can persist soft tagged components by adding --persist flag.
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"'gitlab.bit.branch-laneSource: 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.
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"'gitlab.bit.lane-branchSource: script details
Execute this script when you need to create a new branch importing components from specific bit lane in bit.cloud.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
LANE_NAME: "my-org.my-scope/my-lane-name" # Default lane name, can be overridden from the UI
build-job:
stage: build
script:
- |
cd test-ws
gitlab.bit.init --skip-install
gitlab.bit.lane-branch --lane-name "$LANE_NAME"
rules:
- if: '$LANE_NAME != "main"'
when: manualgitlab.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.
--allow: Allow different types of dependencies. Optionsall,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". Defaultall.--branch: Branch to check for dependency updates. Defaultmain.
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"'You can speed up the CI builds by caching pnpm store using the before_script and cache sections.
image: bitsrc/stable:latest
variables:
GIT_USER_NAME: “git_user_name”
GIT_USER_EMAIL: “git_user_email”
build-job:
stage: build
before_script:
- pnpm config set store-dir .pnpm-store
script:
- |
cd test-ws
gitlab.bit.init
cache:
key:
files:
- test-ws/pnpm-lock.yaml
paths:
- test-ws/.pnpm-store
Note: Replace the directory test-ws with your workspace directory.
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