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
138
Jenkinsfile
vendored
138
Jenkinsfile
vendored
@ -1,55 +1,89 @@
|
|||||||
node {
|
def deploy() {
|
||||||
env.NODE_ENV = 'production'
|
node('ubuntu') {
|
||||||
|
try {
|
||||||
try {
|
stage('Deploy (Ubuntu)') {
|
||||||
stage('Checkout') {
|
checkout scm
|
||||||
checkout scm
|
nodejs(nodeJSInstallationName: 'Node23') {
|
||||||
}
|
sh 'npm ci --include=dev'
|
||||||
|
sh 'npm run build'
|
||||||
stage('Setup Node.js') {
|
// Deploy to Cloudflare Pages using wrangler
|
||||||
nodejs(nodeJSInstallationName: 'Node23') {
|
// CLOUDFLARE_API_TOKEN should be set as a Jenkins credential/env variable
|
||||||
sh 'node -v'
|
sh 'npx wrangler pages deploy build'
|
||||||
sh 'npm -v'
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
cleanWs()
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = '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