Last active
May 7, 2025 10:16
-
-
Save Alex4386/661203229f5873815d6462a5c0736042 to your computer and use it in GitHub Desktop.
PM2 ecosystem.config.js for Jenkins Agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
require('dotenv').config(); | |
} catch(e) { | |
console.error('dotenv not found'); | |
process.exit(1); | |
} | |
const os = require('os'); | |
const path = require('path'); | |
const url = process.env.AGENT_URL; | |
try { | |
if (!url) throw new Error('invalid url'); | |
new URL(url); | |
} catch { | |
console.error('Invalid URL!'); | |
process.exit(1); | |
} | |
const secret = process.env.AGENT_SECRET | |
let cmd = `java -jar agent.jar -url "${url}" -webSocket` | |
if (secret) cmd += ` -secret "${secret}"` | |
const name = process.env.AGENT_NAME || os.hostname(); | |
if (name) cmd += ` -name "${name}"` | |
const workDir = process.env.AGENT_WORKDIR || path.join(process.cwd(), 'work'); | |
if (workDir) cmd += ` -workDir "${workDir}"`; | |
module.exports = { | |
apps : [{ | |
name: "jenkins-agent", | |
cmd, | |
env: { | |
...process.env, | |
}, | |
}], | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Jenkins Agent PM2 Setup | |
# Jenkins server's URL | |
AGENT_URL="https://your-jenkins-server/" | |
# Secret for this agent | |
AGENT_SECRET="replace-this-with-real-one" | |
# Server Name - Fallbacks to hostname if left blank | |
AGENT_NAME="test-node-01" | |
# Working Directory - Fallbacks to ./work if left blank | |
AGENT_WORKDIR="./work" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment