Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How sn-cicd handle data migration #3

Closed
gitlabbin opened this issue Nov 27, 2018 · 10 comments
Closed

How sn-cicd handle data migration #3

gitlabbin opened this issue Nov 27, 2018 · 10 comments
Assignees

Comments

@gitlabbin
Copy link
Contributor

gitlabbin commented Nov 27, 2018

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

  • Configure system properties or other instance-specific settings
  • group or role

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

@bmoers bmoers self-assigned this Nov 29, 2018
@bmoers
Copy link
Owner

bmoers commented Nov 29, 2018

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
Copy link
Contributor Author

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

@gitlabbin
Copy link
Contributor Author

gitlabbin commented Dec 3, 2018

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:

  • Add UI Action into source instance
    https://community.servicenow.com/sys_attachment.do?sys_id=708c1882dbdc17041dcaf3231f9619de

  • Create a new group record "mytest"

  • Click 'Force to updateset' button, the record will insert into current Updateset

  • Use SN-CICD to deploy this updateset

  • Check on target server, the updateset is committed, the updateset having the xml piece of group record "mytest"

  • Check 'System security - Groups' on target server, no any new records created

Any thing wrong with the target server committed the updateset ?

@gitlabbin gitlabbin reopened this Dec 3, 2018
@gitlabbin
Copy link
Contributor Author

gitlabbin commented Dec 3, 2018

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

  • use SNOW 'retrieve updateset' button, find the updateset and then click 'commit update set' button
  • updateset will be 'committed', and 'System security - Groups' on target server, having the right records created

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

@gitlabbin
Copy link
Contributor Author

gitlabbin commented Dec 4, 2018

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
Copy link
Owner

bmoers commented Dec 4, 2018

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
Copy link
Owner

bmoers commented Dec 4, 2018

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
Copy link
Contributor Author

gitlabbin commented Dec 4, 2018

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

@bmoers
Copy link
Owner

bmoers commented Dec 4, 2018

@gitlabbin
Copy link
Contributor Author

Great, close this. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants