Update Confluence (wiki) page by node.js
Getting started.....
# mkdir -p /usr/local/wiki_update_folder
Install confluence-api via npm:
# npm install confluence-api
# vi update_wiki_page_git_version.js
var child = require('child_process')
var Confluence = require("confluence-api");
var config = {
username: "test-user", // your confluence userid
password: "test-pass", // your confluence password
baseUrl: "https://<your_wiki_url>/wiki"
};
var confluence = new Confluence(config);
confluence.getContentByPageTitle("SPACE_NAME", "PAGE_TITLE", function(err, data) {
ver_no = data.results[0].version.number;
ver_no=ver_no+1 ;
child.exec("date",function(err,stdout,stderr){
confluence.putContent("SPACE_NAME","PAGE_ID",ver_no, "PAGE_TITLE",stdout,function(err, data) {});
});
});
e.g:
If you want to display your script output in wiki.
It can be very useful in case you want to publish any status into confluence. Also it can be automated by cron or any task scheduler commands.
var child = require('child_process')
var Confluence = require("confluence-api");
var config = {
username: "testuser",
password: "testpass",
baseUrl: "https://wiki-confluence-url/wiki"
};
var confluence = new Confluence(config);
confluence.getContentByPageTitle("WIKI_SPACE_NAME", "PAGE_TITLE", function(err, data) {
ver_no = data.results[0].version.number;
ver_no=ver_no+1 ;
shell_comm="sh test.sh'";
child.exec(shell_comm,function(err,stdout,stderr){
confluence.putContent("WIKI_SPACE_NAME","WIKI_PAGE_ID",ver_no, "PAGE_TITLE","<pre>"+stdout+"</pre>",function(err, data) {});
});
});
No comments:
Post a Comment