automatic preview and commit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 03:32 AM
Hi,
I just wanted to publish my code for automatic deployment of update sets.
We use this for pushing update sets to test platform.
Input
sys_id
Output
result
report
Code
(function scriptedWebServiceOperation(request, response) {
response.result = 'wrongplatform';
response.report = '';
if(gs.getProperty('sdlc.test') == gs.getProperty('instance_name')) {
// Good we are test platform
response.result = 'missing';
response.report = '';
// Get completed update set from all sources that are active
var gr = new GlideRecord('sys_update_set_source');
gr.get('active', true);
var myworker = new GlideUpdateSetWorker();
myworker.setUpdateSourceSysId(gr.sys_id); // ID of update server
myworker.setBackground(true);
myworker.start();
var progressId = myworker.progressID;
// Wait for a while
var progress = GlideRecord('sys_progress_worker');
for(var i = 0; i < 100000; i++) {
progress.get(progressId);
if(progress.state == 'complete') {
break;
}
}
// Now find the update we are looking for
var remote_updateset = new GlideRecord('sys_remote_update_set');
remote_updateset.addQuery('remote_sys_id', request.sys_id);
remote_updateset.query();
remote_updateset.next();
response.result = remote_updateset.sys_id;
if(!remote_updateset.sys_id.nil()) {
// Mark as previed - see PreviewAjax...
remote_updateset.state = "previewed";
remote_updateset.update();
// Let make sure the reply has some data
response.result = 'previewed';
response.report = gs.getProperty('glide.servlet.uri') + remote_updateset.getLink();
// Well we don't nee a worker
var t = new UpdateSetPreviewer();
// Lets make this rerun safe
t.removePreviewRecords(remote_updateset.sys_id);
t.generatePreviewRecords(remote_updateset.sys_id);
// If all is fine commit
if(!GlidePreviewProblemHandler.hasUnresolvedProblems(remote_updateset.sys_id)) {
var lus = new GlideRecord('sys_update_set');
var worker = new GlideUpdateSetWorker();
var lsysid = worker.remoteUpdateSetCommit(lus, remote_updateset, remote_updateset.update_source.url);
var rsysid = remote_updateset.sys_id;
// great success
response.result = 'commited';
// Copy XML - done by hand in the ScriptInclude so we copy this
var xgr = new GlideRecord("sys_update_xml");
xgr.addQuery("remote_update_set", remote_updateset.sys_id);
xgr.query();
while(xgr.next()) {
var lxgr = new GlideRecord("sys_update_xml");
lxgr.initialize();
lxgr.name = xgr.name;
lxgr.payload = xgr.payload;
lxgr.action = xgr.action;
lxgr.type = xgr.type;
lxgr.target_name = xgr.target_name;
lxgr.view = xgr.view;
lxgr.update_domain = xgr.update_domain;
lxgr.table = xgr.table;
lxgr.category = xgr.category;
lxgr.application = xgr.application;
lxgr.update_set = lsysid;
if (lxgr.isValidField('replace_on_upgrade'))
lxgr.replace_on_upgrade = xgr.replace_on_upgrade;
lxgr.insert();
}
remote_updateset.update();
// Seems odd to send information back to the worker that it provided... but why not.
worker.setUpdateSetSysId(lsysid);
worker.setBackground(false);
worker.start();
}
}
}
})(request, response);
- 2,955 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2016 11:56 PM
Looks like functionality I am looking for, thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2018 12:15 AM
Hi ,
Can you please help me understand what is the significance of using setbackground(true/false) ?
Regards,
Snehal K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2017 10:08 PM
Hi
Just let me know where you have used this code.
If this is used in a processor or a business rule.
It would be helpful if you would let me know the flow of the process.
Thanks
Deepak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 09:53 PM
The above code written is of scripted rest api, which you will have to write in the instance on which you have to retrieve, preview and commit the update set. You can call the API, with appropriate parameters(in this case the sysId of the update set in the local instance).