Certified Jenkins Engineer
Setting up CI Pipeline
Demo Add Jenkinsfile to Solar System Repo
In this tutorial, you’ll learn how to set up a basic Jenkins pipeline for the Solar System repository. We’ll add a Jenkinsfile
at the repo root, push it in a feature branch, and let Jenkins automatically detect and run the pipeline via webhooks.
Prerequisites
- A running Jenkins instance with the Gitea plugin installed.
- A Gitea organization folder configured in Jenkins.
- Access to your Gitea server and the Solar System repository.
Why the Solar System Repo Isn’t Yet in Jenkins
By default, Jenkins scans your Gitea organization folder for repositories containing a Jenkinsfile
. Since Solar System has no pipeline file or webhooks configured, it won’t appear in Jenkins:
1. Clone and Create a Feature Branch
Start by cloning the repo and creating a branch for CI/CD:
git clone <YOUR_SPRINGBOARD_GITEA_URL>/your-org/solar-system.git
cd solar-system
git checkout -b feature/enabling-cicd
2. Add a Basic Jenkinsfile
Open the project in your editor:
Create a file named Jenkinsfile
in the repository root:
pipeline {
agent any
stages {
stage('VM Node Version') {
steps {
sh '''
node -v
npm -v
'''
}
}
}
}
This declarative pipeline runs on any agent and has one stage that prints the Node.js and npm versions.
Commit and push:
git add Jenkinsfile
git commit -m "Add Jenkinsfile for basic pipeline"
git push --set-upstream origin feature/enabling-cicd
3. Confirm Branch and Webhooks in Gitea
After pushing, head to Gitea to verify your branch and watch Jenkins webhooks auto-generate:
You should see two new webhooks for Jenkins delivery:
4. Trigger a Jenkins Scan
Jenkins periodically scans the organization folder for new repositories or branches. You can also kick off a manual scan:
Once scanned, you’ll see the feature/enabling-cicd
branch:
5. View the Multibranch Pipeline
Jenkins creates a multibranch job for solar-system:
Click on the build to inspect stages:
You can also view the pipeline overview:
Pipeline Stages Overview
Stage Name | Purpose | Script |
---|---|---|
Checkout SCM | Clone the repository | Implicit in Declarative |
VM Node Version | Display Node.js and npm versions | node -v <br>npm -v |
6. Use a Jenkins-Managed Node.js Tool
By default, the pipeline uses the host’s Node.js. To leverage a managed tool:
- In Jenkins, go to Pipeline Syntax → Declarative Directive Generator.
- Select tools and pick your Node.js installation (e.g.,
nodejs-22-6-0
). - Copy the snippet and update your
Jenkinsfile
:
pipeline {
agent any
tools {
nodejs 'nodejs-22-6-0'
}
stages {
stage('VM Node Version') {
steps {
sh '''
node -v
npm -v
'''
}
}
}
}
Commit and push the change:
git add Jenkinsfile
git commit -m "Use Jenkins-managed Node.js tool"
git push
Jenkins will automatically run a new build with the managed Node.js:
+ node -v
v22.6.0
+ npm -v
10.8.2
Conclusion
You’ve now:
- Added a
Jenkinsfile
to the Solar System repo - Created webhooks in Gitea
- Triggered Jenkins to scan and build your feature branch
- Configured Jenkins to use a managed Node.js tool
Next, you can extend this pipeline with dependency installation, unit tests, and deployment stages.
Links and References
Watch Video
Watch video content