bmoers / sn-cicd

CICD Server for Service-Now
GNU Lesser General Public License v3.0
44 stars 36 forks source link

How sn-cicd handle data migration #3

Closed gitlabbin closed 5 years ago

gitlabbin commented 5 years ago

When we migrate updateset from dev instance to test instance, some updateset requires additional data or configuration changes.

How will SN-CICD handle it? or any good practice for that case?

bmoers commented 5 years ago

Good point. In ServiceNow its by design that, during a deployment, some actions might need to be done manually, but manual actions actually are not what we want in a CICD pipeline :-/

So all deployment related objects must be part of the updateset.

The 'Create Application File from Record' OOB feature can help to attach such records to an updateset. It actually creates an XML dump of the record into a sys_metadata_link record.

Alternatively the below script can be used to manually add any kind of files to an update-set.

function addToUpdateSet(usSysId, className, sysId) {
    // check if us exists
    var us = new GlideRecord('sys_update_set');
    if (us.get(usSysId)) { 
        // 'Make This My Current Set'
        new GlideUpdateSet().set(usSysId);
    } else {
        throw Error('Updateset not found' + usSysId);
    }

    var gr = new GlideRecord(className);
    if (gr.get(sysId)) {
        // add record to update-set
        new GlideUpdateManager2().saveRecord(gr);
        gs.info("done");
    } else {
        gs.info("record not found: " + className + ':' + sysId);
    }
}

There is also the option to create an UI action with the above script to allwo to collect records to US from the UI.

If a deployment requires some script to be executed post go-live, there is also an option to create a scheduler (sysauto_script) with all scripts. After a successful run, the scheduler can disabling (or even delete) itself.

gitlabbin commented 5 years ago

Thanks @bmoers , will try it. close it now.

gitlabbin commented 5 years ago

Update set with 'group' data records committed successfully, but the data record can't be see from system groups:

Source and Target servers:
two free instances ServiceNow (glide-london-06-27-2018__patch1-08-15-2018_08-22-2018_1559)

Steps to produce:

Any thing wrong with the target server committed the updateset ?

gitlabbin commented 5 years ago

More tests: using the same updateset generated from above steps On target server:

Any difference between SN-CICD commit vs. SNOW commit update set button?

gitlabbin commented 5 years ago

sn-cicd-integration:

https://github.com/bmoers/sn-cicd-integration/blob/276769a0e177ee508460d5b41e7a3c66d48b6e1f/script_include/CiCdDeploy.js#L599-L616

Turn out this code working:

            var commitResult = new UpdateSetCommitAjax((function () {
                var params = {
                    sysparm_type: 'commitRemoteUpdateSet',
                    sysparm_remote_updateset_sys_id: payload.remoteUpdateSetSysId
                };
                return {
                    getParameter: function (paramName) {
                        return params[paramName];
                    }
                };
            })(), new GlideXMLDocument(), '').process();
            var progress_id = commitResult.split(',')[0];

The following one can't handle the data record of the update set

            var worker = new SNC.HierarchyUpdateSetScriptable();
            var progress_id = worker.commitHierarchy(payload.remoteUpdateSetSysId);

@bmoers , Can you please confirm my finding?

bmoers commented 5 years ago

Seems the HierarchyUpdateSetCommitAjax does not work for forced records. @gitlabbin can you check if forced records in hierarchical update-sets get installed (with 'new SNC.HierarchyUpdateSetScriptable()' ..)

The 'commitRemoteUpdateSet' only works for non-hierarchical update-sets. So it requires a check first to run either or.

Let me check.

bmoers commented 5 years ago

I was not able to reproduce the issue. @gitlabbin can you please share the update-set you tested?

Attached the one I have used. Test - No Parent- sys_remote_update_set_459ab967db42230051cefbef29961993.zip

gitlabbin commented 5 years ago

The simple updateset just with a group record: please look at here https://gist.github.com/gitlabbin/0409792d54f921700688154532ffa9a5

bmoers commented 5 years ago

Deployed a fix in https://github.com/bmoers/sn-cicd-integration/commit/7d3d70c1cdb66125d841fbedb9e440d32c62b64d
Please take latest update-set from here https://github.com/bmoers/sn-cicd-integration/blob/master/update_set/CICD%20Integration.xml

gitlabbin commented 5 years ago

Great, close this. 👍