![JENKINS & NODE.JS cover](https://i0.wp.com/www.qahive.com/wp-content/uploads/2021/07/JENKINS-NODE.JS-cover.png?resize=696%2C466&ssl=1)
Build Node.js Project บน Jenkins สิ่งที่ต้องเตรียมก่อนคือ Install Nodejs บนเครื่อง Jenkins Server ก่อนที่เราจะ Config pipeline script กัน
![](https://i0.wp.com/www.qahive.com/wp-content/uploads/2021/07/image-7.png?resize=696%2C268&ssl=1)
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
สนใจเรียนคอร์สออนไลน์เพิ่มเติมด้านล่างเลย
![](https://i0.wp.com/www.qahive.com/wp-content/uploads/2021/08/ci-cd-jenkins-course-qahive-1.png?w=696&ssl=1)
CI & CD ด้วย Jenkins Pipeline
เรียนคอร์ส Jenkins Online ก่อนใคร
จาก 3,000 ลดเหลือ 2,499 บาทเท่านั้น!!!