Using scipted ci

This commit is contained in:
Tom Butcher 2025-06-01 21:55:20 +01:00
parent dc84580615
commit 8bfb22db0f

72
Jenkinsfile vendored
View File

@ -1,64 +1,46 @@
pipeline { node {
agent any env.NODE_ENV = 'production'
environment { try {
NODE_ENV = 'production'
}
stages {
stage('Setup Node.js') { stage('Setup Node.js') {
steps { nodejs(nodeJSInstallationName: 'Node23') {
nodejs(nodeJSInstallationName: 'Node23') { sh 'node -v'
sh 'node -v' sh 'npm -v'
sh 'npm -v'
}
} }
} }
stage('Install Dependencies') { stage('Install Dependencies') {
steps { nodejs(nodeJSInstallationName: 'Node23') {
nodejs(nodeJSInstallationName: 'Node23') { sh 'npm ci --include=dev'
sh 'npm ci --include=dev'
}
} }
} }
stage('Build') { stage('Build') {
steps { nodejs(nodeJSInstallationName: 'Node23') {
nodejs(nodeJSInstallationName: 'Node23') { sh 'npm run build'
sh 'npm run build'
}
} }
} }
stage('Deploy to printer1') { stage('Deploy to printer1') {
steps { def remote = [:]
script { remote.name = 'printer1'
def remote = [:] remote.host = 'printer1.tombutcher.local'
remote.name = 'printer1' remote.user = 'ci'
remote.host = 'printer1.tombutcher.local' romote.password = 'ci'
remote.user = 'ci' remote.allowAnyHosts = true
remote.password = 'ci'
remote.allowAnyHosts = true
// Upload the build folder
sshPut remote: remote, from: 'build/', into: '/srv/farmcontrol-server/'
// Restart the service // Copy the build directory to the remote server
sshCommand remote: remote, command: 'sudo /bin/systemctl restart farmcontrol-server.service' sshPut remote: remote, from: 'build/', into: '/srv/farmcontrol-server/'
}
}
}
}
post { // Restart the service using sudo
always { sshCommand remote: remote, command: 'sudo /bin/systemctl restart farmcontrol-server.service'
cleanWs()
}
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed!'
} }
echo 'Pipeline completed successfully!'
} catch (Exception e) {
echo 'Pipeline failed!'
throw e
} finally {
cleanWs()
} }
} }