
Build Node.js Project บน Jenkins สิ่งที่ต้องเตรียมก่อนคือ Install Nodejs บนเครื่อง Jenkins Server ก่อนที่เราจะ Config pipeline script กัน

Prepare Node.js environment
- ทำการติดตั้ง Node.js application บนเครื่อง Jenkins server https://nodejs.org/en/
- ทำการ Restart เครื่อง Jenkins server เพื่อ reload environment variable
Config Pipeline script
- สร้าง Pipeline Job ได้ไปที่ New Item แล้วเลือกประเภทโปรเจคเป็น Pipeline
- Copy ตัวอย่าง Code นี้ไปแปะใน Pipeline Script ได้เลย
pipeline {
agent any
stages {
stage('Build') {
steps {
git 'https://github.com/atthaboon/quick-example-of-testing-in-nodejs.git'
bat "npm install"
}
}
stage('Unit test') {
steps {
bat "npm test"
}
post {
success {
junit '**/test-results.xml'
}
}
}
}
}
3. Save แล้วสั่งรัน Build ได้เลย
อธิบาย Pipeline Code
- git ‘https://github.com/atthaboon/quick-example-of-testing-in-nodejs.git’
ใช้ Git clone source code จาก Github - bat “npm install” & “npm test”
รัน command npm ในการสร้าง install และ run test - junit ‘**/target/surefire-reports/TEST-*.xml’
ทำการอ่าน junit test result ที่ได้จากการรัน package
สนใจเรียนคอร์สออนไลน์เพิ่มเติมด้านล่างเลย

CI & CD ด้วย Jenkins Pipeline
เรียนคอร์ส Jenkins Online ก่อนใคร
จาก 3,000 ลดเหลือ 2,499 บาทเท่านั้น!!!