farmcontrol-server/Jenkinsfile
2025-06-01 22:02:32 +01:00

55 lines
1.5 KiB
Groovy

node {
env.NODE_ENV = 'production'
try {
stage('Checkout') {
checkout scm
}
stage('Setup Node.js') {
nodejs(nodeJSInstallationName: 'Node23') {
sh 'node -v'
sh 'npm -v'
}
}
stage('Install Dependencies') {
nodejs(nodeJSInstallationName: 'Node23') {
sh 'npm ci --include=dev'
}
}
stage('Build') {
nodejs(nodeJSInstallationName: 'Node23') {
sh 'npm run build'
sh 'ls -la build || echo "Build directory not found"'
}
}
stage('Verify Build') {
sh 'test -d build || (echo "Build directory does not exist" && exit 1)'
}
stage('Deploy to printer1') {
def remote = [:]
remote.name = 'printer1'
remote.host = 'printer1.tombutcher.local'
remote.user = 'ci'
remote.password = 'ci'
remote.allowAnyHosts = true
// Copy the build directory to the remote server
sshPut remote: remote, from: 'build/*', into: '/srv/farmcontrol-server/'
// Restart the service using sudo
sshCommand remote: remote, command: 'sudo /bin/systemctl restart farmcontrol-server.service'
}
echo 'Pipeline completed successfully!'
} catch (Exception e) {
echo 'Pipeline failed!'
throw e
} finally {
cleanWs()
}
}