2018-04-04 20:25:13 +00:00
|
|
|
import * as plugins from './mod.plugins';
|
|
|
|
import { bash } from '../npmci.bash';
|
2016-06-01 04:30:21 +00:00
|
|
|
|
2018-04-04 20:25:13 +00:00
|
|
|
let triggerValueRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/;
|
2016-06-23 20:22:03 +00:00
|
|
|
|
2017-03-08 13:50:41 +00:00
|
|
|
export let trigger = async () => {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.info('now running triggers');
|
|
|
|
plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TRIGGER_*', evaluateTrigger);
|
|
|
|
};
|
2016-06-23 20:22:03 +00:00
|
|
|
|
2018-04-04 20:25:13 +00:00
|
|
|
let evaluateTrigger = async triggerEnvVarArg => {
|
|
|
|
let triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg);
|
|
|
|
let regexDomain = triggerRegexResultArray[1];
|
|
|
|
let regexProjectId = triggerRegexResultArray[2];
|
|
|
|
let regexProjectTriggerToken = triggerRegexResultArray[3];
|
|
|
|
let regexRefName = triggerRegexResultArray[4];
|
|
|
|
let regexTriggerName;
|
2017-03-08 13:50:41 +00:00
|
|
|
if (triggerRegexResultArray.length === 6) {
|
2018-04-04 20:25:13 +00:00
|
|
|
regexTriggerName = triggerRegexResultArray[5];
|
2017-03-08 13:50:41 +00:00
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
regexTriggerName = 'Unnamed Trigger';
|
2017-03-08 13:50:41 +00:00
|
|
|
}
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.info('Found Trigger!');
|
|
|
|
plugins.beautylog.log('triggering build for ref ' + regexRefName + ' of ' + regexTriggerName);
|
2018-09-22 12:36:25 +00:00
|
|
|
plugins.request.postFormData(
|
|
|
|
'https://gitlab.com/api/v3/projects/' + regexProjectId + '/trigger/builds',
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'token',
|
|
|
|
payload: regexProjectTriggerToken,
|
|
|
|
type: 'string'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'ref',
|
|
|
|
payload: regexRefName,
|
|
|
|
type: 'string'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|