Updated Jenkins file to work on 3x nodes.
Some checks reported errors
farmcontrol/farmcontrol-ui/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
farmcontrol/farmcontrol-ui/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
parent
84e98aa626
commit
9ef8874418
122
Jenkinsfile
vendored
122
Jenkinsfile
vendored
@ -1,55 +1,89 @@
|
||||
node {
|
||||
env.NODE_ENV = 'production'
|
||||
|
||||
def deploy() {
|
||||
node('ubuntu') {
|
||||
try {
|
||||
stage('Checkout') {
|
||||
stage('Deploy (Ubuntu)') {
|
||||
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"'
|
||||
// Deploy to Cloudflare Pages using wrangler
|
||||
// CLOUDFLARE_API_TOKEN should be set as a Jenkins credential/env variable
|
||||
sh 'npx wrangler pages deploy build'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Verify Build') {
|
||||
sh 'test -d build || (echo "Build directory does not exist" && exit 1)'
|
||||
}
|
||||
|
||||
stage('Deploy to printer1') {
|
||||
def remote = [:]
|
||||
remote.name = 'farmcontrolserver'
|
||||
remote.host = 'farmcontrol.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-ui/'
|
||||
|
||||
// Restart the service using sudo
|
||||
sshCommand remote: remote, command: 'sudo /bin/systemctl restart nginx.service'
|
||||
}
|
||||
|
||||
echo 'Pipeline completed successfully!'
|
||||
} catch (Exception e) {
|
||||
echo 'Pipeline failed!'
|
||||
throw e
|
||||
} finally {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def buildOnLabel(label, buildCommand) {
|
||||
return {
|
||||
node(label) {
|
||||
env.NODE_ENV = 'production'
|
||||
try {
|
||||
stage("Checkout (${label})") {
|
||||
checkout scm
|
||||
}
|
||||
|
||||
stage("Setup Node.js (${label})") {
|
||||
nodejs(nodeJSInstallationName: 'Node23') {
|
||||
if (isUnix()) {
|
||||
sh 'node -v'
|
||||
sh 'npm -v'
|
||||
} else {
|
||||
bat 'node -v'
|
||||
bat 'npm -v'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage("Install Dependencies (${label})") {
|
||||
nodejs(nodeJSInstallationName: 'Node23') {
|
||||
if (isUnix()) {
|
||||
sh 'npm ci --include=dev'
|
||||
} else {
|
||||
bat 'npm ci --include=dev'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage("Build (${label})") {
|
||||
nodejs(nodeJSInstallationName: 'Node23') {
|
||||
if (isUnix()) {
|
||||
sh buildCommand
|
||||
sh 'ls -la build || echo "Build directory not found"'
|
||||
} else {
|
||||
bat buildCommand
|
||||
bat 'if not exist build echo "Build directory not found"'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage("Verify Build (${label})") {
|
||||
if (isUnix()) {
|
||||
sh 'test -d build || (echo "Build directory does not exist" && exit 1)'
|
||||
} else {
|
||||
bat 'if not exist build (echo "Build directory does not exist" && exit 1)'
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
parallel(
|
||||
'Windows Build': buildOnLabel('windows', 'npm run build:electron'),
|
||||
'MacOS Build': buildOnLabel('macos', 'npm run build:electron'),
|
||||
'Ubuntu Deploy': { deploy() }
|
||||
)
|
||||
|
||||
echo 'All parallel stages completed successfully!'
|
||||
|
||||
} catch (Exception e) {
|
||||
echo "Pipeline failed: ${e.message}"
|
||||
throw e
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user