Example Jenkin Files for common Bit and Git CI/CD workflows.
-
Jenkins Setup
- Install Jenkins. Example Setting up Jenkins in AWS Guide.
- Install Docker Pipeline Plugin.
- Ensure that your Build Nodes can run docker. Example If you use the Jenkins Host to run build tasks in an Amazon Linux instance, use the following steps.
- Update the System:
sudo yum update - Install Docker:
sudo yum install docker - Start and Enable Docker:
sudo service docker start sudo chkconfig docker on - Add Jenkins User to Docker Group:
sudo usermod -aG docker jenkins - Verify Docker Installation:
docker --version - Restart Jenkins (If on Host):
sudo service jenkins restart
- Update the System:
-
Use BIT_CONFIG_USER_TOKEN (docs).
-
Follow steps
New Items -> Pipeline -> Pipeline scriptand select any of the scripts inside thejenkins-filesand copy-paste its content.Following is an example Jenkins CI/CD pipeline script of checking the Bit version available in the docker container.
pipeline { agent { docker { image 'bitsrc/stable:latest' args '-u root --privileged' } } environment { GIT_USER_NAME = 'git_user_name' GIT_USER_EMAIL = 'git_user_email' BIT_CONFIG_USER_TOKEN = 'bit_config_access_token' } stages { stage('Test Bit Version') { steps { script { sh ''' bit -v ''' } } } } }
You can configure support through the Bit Docker image. Select from these available images:
-
Latest Stable:
bitsrc/stable:latest -
Nightly:
bitsrc/nightly:latest
| Task | Example |
|---|---|
| Initialize Bit | jenkins-files/bit-init |
| Bit Verify Components | jenkins-files/verify |
| Bit Tag and Export | jenkins-files/tag-export |
| Bit Merge Request Build | jenkins-files/pull-request |
| Bit Lane Cleanup | jenkins-files/lane-cleanup |
| Commit Bitmap | jenkins-files/commit-bitmap |
| Task | Example |
|---|---|
| Dependency Update | jenkins-files/bit-dependency-update |
| Task | Example |
|---|---|
| Branch Lane | jenkinbs-files/bit-branch-lane |
| Lane Branch | jenkinbs-files/bit-lane-branch |
You can use the Bit commands referring to the Bit shell script examples and add additional functionality depending on your Git version control platform (e.g GitHub or GitLab).
Source: script details
The Bit Docker image comes with the latest Bit version pre-installed. Therefore, you only need to run bit install inside the workspac directory in your script.
pipeline {
agent {
docker {
image 'bitsrc/stable:latest'
args '-u root --privileged'
}
}
environment {
GIT_USER_NAME = 'git_user_name'
GIT_USER_EMAIL = 'git_user_email'
BIT_CONFIG_USER_TOKEN = 'bit_config_access_token'
}
stages {
stage('Build') {
steps {
script {
sh '''
cd "my-workspace-directory"
bit install
'''
}
}
}
}
post {
always {
script {
cleanWs()
}
}
}
}
If you need to install a different version of Bit, you can include the following script.
BIT_VERSION="0.2.8"
# install bvm and bit
npm i -g @teambit/bvm
bvm install ${BIT_VERSION} --use-system-node
export PATH="${HOME}/bin:${PATH}" # This step may change depending on your CI runner
cd "my-workspace-directory"
bit installSource: script details
pipeline {
agent {
docker {
image 'bitsrc/stable:latest'
args '-u root --privileged'
}
}
environment {
GIT_USER_NAME = 'git_user_name'
GIT_USER_EMAIL = 'git_user_email'
BIT_CONFIG_USER_TOKEN = 'bit_config_access_token'
}
stages {
stage('Build') {
steps {
script {
sh '''
# added from bit-init.sh
cd "my-workspace-directory"
bit install
# added from bit-verify.sh
bit status --strict
bit build
'''
}
}
}
}
post {
always {
script {
cleanWs()
}
}
}
}
For other Bit and Git CI/CD pipelines tasks refer Shell Scripts.
You can speed up the CI builds by caching the pnpm store by mounting it from the Jenkins host.
pipeline {
agent {
docker {
image 'bitsrc/stable:latest'
args '-u root --privileged -v /jenkins/caches/my-workspace-directory/.pnpm-store:/my-workspace-directory/.pnpm-store'
}
}
environment {
GIT_USER_NAME = 'git_user_name'
GIT_USER_EMAIL = 'git_user_email'
BIT_CONFIG_USER_TOKEN = 'bit_config_access_token'
PNPM_STORE = '/my-workspace-directory/.pnpm-store' // Define the environment variable for the pnpm store path
}
stages {
stage('Build') {
steps {
script {
sh '''
# Configure pnpm to use the mounted cache directory
pnpm config set store-dir $PNPM_STORE
# Proceed with bit and pnpm commands
cd "my-workspace-directory"
bit install
# Verify and build operations
bit status --strict
bit build
'''
}
}
}
}
post {
always {
script {
cleanWs(notFailBuild: true)
}
}
}
}
Note: The exact volume path that you mount may depend on your Jenkins host configuration.
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