This project was bootstrapped with Create React App.
This project is node.js. So we need node runtime environment to run javascript. However, Jenkins does not provide default node environment, Therefore we will be using docker container
dashboard - > Jenkins setting -> plugin -> docker pipeline
Then , we are able to use docker container in pippeline
pipeline{
agent any
stages{
stage('w/ docker'){
agent{
docker{
image 'node:18-alpine'
}
}
}
}
}
docker will pull the image if it has not been installed.
when using docker, I used agent stage twice and it made my workspace created seperately
To avoid that, we can use reuseNode true.
pipeline {
agent any
stages {
stage('w/o docker') {
steps {
sh '''
echo "without docker"
ls -la
touch container-no.txt
'''
}
}
stage('w/ docker') {
agent{
docker{
image 'node:18-alpine'
reuseNode true
}
}
steps {
sh '''
echo "with docker"
ls -la
touch container-yes.txt
'''
}
}
}
}
create Jenkinsfile in root directory on workspace
Then, Write the pipeline that you want to buid in Jenkinsfile
After that, go to Jenkins ,
In the configure -> pipeline, simply switch definition pipeline to "pipeline script from scm(Source Code Management)"
Then write as follows
After completing everything, build Jenkins and it's complete.
If we have changes in Jenkinsfile, push to git again and build again.