Setting up CI/CD for website via Jenkins
Jenkins—mature open-source automation. Requires own server, but no limits on minutes, agents, parallel builds. For organizations with strict infrastructure isolation or large build volumes—justified choice.
Installation
# Ubuntu 22.04, Java 17 required
apt install fontconfig openjdk-17-jre
wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
apt update && apt install jenkins
systemctl enable --now jenkins
# Available on :8080
Minimum: 2 CPU, 4 GB RAM.
Declarative Pipeline (Jenkinsfile)
pipeline {
agent any
tools {
nodejs 'NodeJS-20'
}
environment {
DEPLOY_HOST = credentials('deploy-host')
DEPLOY_KEY = credentials('deploy-ssh-key')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Install') {
steps {
sh 'npm ci'
}
}
stage('Test') {
steps {
sh 'npm test'
}
post {
always {
junit 'test-results/**/*.xml'
}
}
}
stage('Build') {
steps {
sh 'npm run build'
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
sshagent(['deploy-ssh-key']) {
sh '''
rsync -avz --delete dist/ deploy@${DEPLOY_HOST}:/var/www/mysite/
'''
}
}
}
}
post {
failure {
telegramSend(message: "Build failed: ${env.JOB_NAME}", chatId: '...')
}
}
}
Credentials management
Manage Jenkins → Credentials → Secret text, SSH keys, certificates. Never in code.
withCredentials([
string(credentialsId: 'telegram-token', variable: 'TG_TOKEN')
]) {
sh 'echo $TG_TOKEN'
}
Parallel stages
stage('Test & Lint') {
parallel {
stage('Unit Tests') {
steps { sh 'npm test' }
}
stage('Lint') {
steps { sh 'npm run lint' }
}
}
}
Docker agents
pipeline {
agent none
stages {
stage('Build') {
agent {
docker {
image 'node:20-alpine'
}
}
steps {
sh 'npm ci && npm run build'
}
}
}
}
Setup time: 2-3 days for server + first working pipeline.







