Version 0.5.0 - Ajout des pipelines
All checks were successful
Neutral/pipeline/head This commit looks good
All checks were successful
Neutral/pipeline/head This commit looks good
This commit is contained in:
138
bin/pipelines.js
Normal file
138
bin/pipelines.js
Normal file
@ -0,0 +1,138 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { __glob } = require("./global-variables")
|
||||
const clog = new LogType("Pïpeline")
|
||||
const config = require("./config")
|
||||
|
||||
const tokenkey = config.getFile().JENKINS_TOKEN
|
||||
|
||||
module.exports.getAllPipelines = function() {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
fetch(`https://jenkins.raphix.fr/api/json`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Authorization": `Basic ${tokenkey}`
|
||||
},
|
||||
credentials: "include"
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(async list => {
|
||||
|
||||
const pipelinesJobs = new Array()
|
||||
|
||||
for(const job of list.jobs) {
|
||||
await fetch(`${job.url}/api/json`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Authorization": `Basic ${tokenkey}`
|
||||
},
|
||||
credentials: "include"
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(async res => {
|
||||
|
||||
if(res._class == "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject") {
|
||||
await getJobMain(res).then(resJ => {
|
||||
res.jobs[0] = resJ
|
||||
pipelinesJobs.push(res)
|
||||
})
|
||||
} else {
|
||||
pipelinesJobs.push(res)
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
list.jobs = pipelinesJobs
|
||||
|
||||
resolve(list)
|
||||
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
resolve("UNAVAILABLE")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports.startPipeline = function(pipeline) {
|
||||
|
||||
|
||||
// If it's a freestyle job, build with params
|
||||
|
||||
if(pipeline.type == "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject") {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(`${pipeline.url}/job/${pipeline.jobname}/build?delay=0sec`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Basic ${tokenkey}`
|
||||
},
|
||||
credentials: "include"
|
||||
})
|
||||
.then(res => {
|
||||
resolve("OK")
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const parameters = pipeline.fields
|
||||
|
||||
const formatedParams = new URLSearchParams()
|
||||
|
||||
for(const param of parameters) {
|
||||
formatedParams.append(param.name, param.value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fetch(`${pipeline.url}/buildWithParameters?delay=0sec`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Basic ${tokenkey}`,
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
credentials: "include",
|
||||
body: formatedParams
|
||||
})
|
||||
.then(res => {
|
||||
resolve("OK")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getJobMain(res) {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
await fetch(`${res.jobs[0].url}/api/json`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': `Basic ${tokenkey}`
|
||||
},
|
||||
credentials: 'include'
|
||||
}).then(res => res.json())
|
||||
.then(res => {
|
||||
resolve(res)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ const auth = require("./auth.js")
|
||||
const files = require("./files.js")
|
||||
const links = require("./links.js")
|
||||
const service = require("./services.js")
|
||||
const pipeline = require("./pipelines.js")
|
||||
const plog = new LogType("Web")
|
||||
const cook = require("cookie")
|
||||
const http = require("http")
|
||||
@ -49,56 +50,56 @@ module.exports.serverIO = function(server) {
|
||||
|
||||
if(user.checkPermission("FILES_EXPLORER")) {
|
||||
|
||||
PostRequest("FX_GET", (root) => {
|
||||
PostRequest("FX_GET", (root) => {
|
||||
|
||||
PostAnswer("FX_GET", files.getFiles(root))
|
||||
})
|
||||
PostAnswer("FX_GET", files.getFiles(root))
|
||||
})
|
||||
|
||||
PostRequest("FX_NEW_FOLDER", (root) => {
|
||||
PostRequest("FX_NEW_FOLDER", (root) => {
|
||||
|
||||
PostAnswer("FX_NEW_FOLDER", files.createFolder(root))
|
||||
})
|
||||
PostAnswer("FX_NEW_FOLDER", files.createFolder(root))
|
||||
})
|
||||
|
||||
PostRequest("FX_DELETE", (root) => {
|
||||
PostRequest("FX_DELETE", (root) => {
|
||||
|
||||
PostAnswer("FX_DELETE", files.deleteFile(root))
|
||||
} )
|
||||
PostAnswer("FX_DELETE", files.deleteFile(root))
|
||||
} )
|
||||
|
||||
PostRequest("FX_RENAME", (settings) => {
|
||||
|
||||
PostAnswer("FX_RENAME", files.renameFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_SHARE", (settings) => {
|
||||
PostRequest("FX_RENAME", (settings) => {
|
||||
|
||||
PostAnswer("FX_SHARE", files.shareFile(settings))
|
||||
})
|
||||
PostAnswer("FX_RENAME", files.renameFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_GETFILE", (root) => {
|
||||
|
||||
PostAnswer("FX_GETFILE", files.getFile(root))
|
||||
})
|
||||
PostRequest("FX_SHARE", (settings) => {
|
||||
|
||||
PostAnswer("FX_SHARE", files.shareFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_SAVEFILE", (settings) => {
|
||||
|
||||
PostAnswer("FX_SAVEFILE", files.saveFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_NEW_FILE", (settings) => {
|
||||
PostRequest("FX_GETFILE", (root) => {
|
||||
|
||||
PostAnswer("FX_NEW_FILE", files.newFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_UPLOAD", (settings) => {
|
||||
PostAnswer("FX_GETFILE", files.getFile(root))
|
||||
})
|
||||
|
||||
PostAnswer("FX_UPLOAD", files.uploadFile(settings))
|
||||
PostRequest("FX_SAVEFILE", (settings) => {
|
||||
|
||||
PostAnswer("FX_SAVEFILE", files.saveFile(settings))
|
||||
})
|
||||
|
||||
})
|
||||
PostRequest("FX_NEW_FILE", (settings) => {
|
||||
|
||||
PostAnswer("FX_NEW_FILE", files.newFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_UPLOAD", (settings) => {
|
||||
|
||||
PostRequest("FX_PASTE", (settings) => {
|
||||
|
||||
PostAnswer("FX_PASTE", files.pasteFile(settings))
|
||||
})
|
||||
PostAnswer("FX_UPLOAD", files.uploadFile(settings))
|
||||
|
||||
})
|
||||
|
||||
PostRequest("FX_PASTE", (settings) => {
|
||||
|
||||
PostAnswer("FX_PASTE", files.pasteFile(settings))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@ -151,6 +152,17 @@ module.exports.serverIO = function(server) {
|
||||
});
|
||||
}
|
||||
|
||||
if(user.checkPermission("PIPELINES")) {
|
||||
GetRequest("PL_GET_ALL", async () => {
|
||||
GetAnswer("PL_GET_ALL", await pipeline.getAllPipelines())
|
||||
})
|
||||
|
||||
PostRequest("PL_START", async (settings) => {
|
||||
PostAnswer("PL_START", await pipeline.startPipeline(settings))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
|
||||
plog.log("Déconnexion du panel par '" + user.username + "' avec le socket : " + socket.id)
|
||||
|
Reference in New Issue
Block a user