-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (33 loc) · 1.14 KB
/
Copy pathscript.js
File metadata and controls
40 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const express = require('express');
const axios = require('axios');
const path = require('path');
const app = express();
const port = 3000;
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));
// Endpoint to trigger Jenkins job
app.post('/trigger-build', async (req, res) => {
const jenkinsUrl = 'http://jenkins-server/job/your-job-name/buildWithParameters';
const jenkinsToken = 'your-jenkins-token';
try {
const response = await axios.post(jenkinsUrl, null, {
params: {
token: jenkinsToken
},
auth: {
username: 'your-jenkins-username',
password: 'your-jenkins-api-token'
}
});
res.status(200).json({ message: 'Build triggered successfully!' });
} catch (error) {
console.error('Error triggering Jenkins job:', error);
res.status(500).json({ message: 'Failed to trigger build' });
}
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`);
});