I am currently setting up Continuous Integration and Continuous Deployment (CI/CD) for a Next.js application using Jenkins Pipeline. While I have successfully connected my GitHub repository and set up webhooks, I am facing difficulties with writing the JenkinsFile Pipeline script.
My environment consists of Ubuntu 16.04, and I have multiple Next.js applications deployed using PM2 and Apache. Previously, I manually handled updates by navigating to the project directory on the Ubuntu server and executing commands like git pull
, npm install
, npm run build
, and pm2 reload
to deploy updates. However, I am looking to remove the downtime during builds and PM2 reloads by integrating Jenkins into my workflow.(I’m not sure it’s possible to get rid of downtime.)
Although I have made progress with setting up Jenkins, I am stuck at the part where I need to write the JenkinsFile script.
pipeline {
agent any
stages {
stage("Build") {
steps {
sh "npm install"
sh "npm run build"
}
}
stage("Deploy") {
steps {
script {
// Unsure how to proceed with the deployment stage
}
}
}
}
}
In the above JenkinsFile, I encountered the error message: “npm command not found” when attempting to run npm install
. (I attempted to install npm on the Jenkins container using apt-get, but I encountered a ‘Permission denied’ error. Unsure if this approach was correct, and unable to find similar cases, I halted at this point.) Additionally, I am unsure about how to proceed with the deployment stage (Deploy) given my current setup.
I would greatly appreciate any guidance on resolving the npm command not found issue and properly configuring the JenkinsFile.