export function setVariable()

in node/task.ts [163:189]


export function setVariable(name: string, val: string, secret: boolean = false, isOutput: boolean = false): void {
    // once a secret always a secret
    let key: string = im._getVariableKey(name);
    if (im._knownVariableMap.hasOwnProperty(key)) {
        secret = secret || im._knownVariableMap[key].secret;
    }

    // store the value
    let varValue = val || '';
    debug('set ' + name + '=' + (secret && varValue ? '********' : varValue));
    if (secret) {
        if (varValue && varValue.match(/\r|\n/) && `${process.env['SYSTEM_UNSAFEALLOWMULTILINESECRET']}`.toUpperCase() != 'TRUE') {
            throw new Error(loc('LIB_MultilineSecret'));
        }

        im._vault.storeSecret('SECRET_' + key, varValue);
        delete process.env[key];
    } else {
        process.env[key] = varValue;
    }

    // store the metadata
    im._knownVariableMap[key] = <im._KnownVariableInfo>{ name: name, secret: secret };

    // write the setvariable command
    command('task.setvariable', { 'variable': name || '', isOutput: (isOutput || false).toString(), 'issecret': (secret || false).toString() }, varValue);
}